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 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 369 | static struct shell_seat * |
| 370 | get_shell_seat(struct weston_seat *seat); |
| 371 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 372 | static bool |
| 373 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 374 | { |
| 375 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 376 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 377 | |
| 378 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 379 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 380 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 381 | return false; |
| 382 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 383 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 384 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 385 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 386 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 387 | } |
| 388 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 389 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 390 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 391 | { |
| 392 | struct shell_grab *grab; |
| 393 | |
| 394 | grab = container_of(listener, struct shell_grab, |
| 395 | shsurf_destroy_listener); |
| 396 | |
| 397 | grab->shsurf = NULL; |
| 398 | } |
| 399 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 400 | static struct weston_view * |
| 401 | get_default_view(struct weston_surface *surface) |
| 402 | { |
| 403 | struct shell_surface *shsurf; |
| 404 | struct weston_view *view; |
| 405 | |
| 406 | if (!surface || wl_list_empty(&surface->views)) |
| 407 | return NULL; |
| 408 | |
| 409 | shsurf = get_shell_surface(surface); |
| 410 | if (shsurf) |
| 411 | return shsurf->view; |
| 412 | |
| 413 | wl_list_for_each(view, &surface->views, surface_link) |
| 414 | if (weston_view_is_mapped(view)) |
| 415 | return view; |
| 416 | |
| 417 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 418 | } |
| 419 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 420 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 421 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 422 | |
| 423 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 424 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 425 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 426 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 427 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 428 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 429 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 430 | struct desktop_shell *shell = shsurf->shell; |
| 431 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 432 | popup_grab_end(pointer); |
| 433 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 434 | grab->grab.interface = interface; |
| 435 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 436 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 437 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 438 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 439 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 440 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 441 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 442 | if (shell->child.desktop_shell) { |
| 443 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 444 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 445 | weston_pointer_set_focus(pointer, |
| 446 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 447 | wl_fixed_from_int(0), |
| 448 | wl_fixed_from_int(0)); |
| 449 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 453 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 454 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 455 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 456 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 457 | grab->shsurf->grabbed = 0; |
| 458 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 459 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 460 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 464 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 465 | const struct weston_touch_grab_interface *interface, |
| 466 | struct shell_surface *shsurf, |
| 467 | struct weston_touch *touch) |
| 468 | { |
| 469 | struct desktop_shell *shell = shsurf->shell; |
| 470 | |
| 471 | grab->grab.interface = interface; |
| 472 | grab->shsurf = shsurf; |
| 473 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 474 | wl_signal_add(&shsurf->destroy_signal, |
| 475 | &grab->shsurf_destroy_listener); |
| 476 | |
| 477 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 478 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 479 | |
| 480 | weston_touch_start_grab(touch, &grab->grab); |
| 481 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 482 | weston_touch_set_focus(touch->seat, |
| 483 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static void |
| 487 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 488 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 489 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 490 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 491 | grab->shsurf->grabbed = 0; |
| 492 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 493 | |
| 494 | weston_touch_end_grab(grab->touch); |
| 495 | } |
| 496 | |
| 497 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 498 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 499 | struct weston_output *output); |
| 500 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 501 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 502 | get_modifier(char *modifier) |
| 503 | { |
| 504 | if (!modifier) |
| 505 | return MODIFIER_SUPER; |
| 506 | |
| 507 | if (!strcmp("ctrl", modifier)) |
| 508 | return MODIFIER_CTRL; |
| 509 | else if (!strcmp("alt", modifier)) |
| 510 | return MODIFIER_ALT; |
| 511 | else if (!strcmp("super", modifier)) |
| 512 | return MODIFIER_SUPER; |
| 513 | else |
| 514 | return MODIFIER_SUPER; |
| 515 | } |
| 516 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 517 | static enum animation_type |
| 518 | get_animation_type(char *animation) |
| 519 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 520 | if (!strcmp("zoom", animation)) |
| 521 | return ANIMATION_ZOOM; |
| 522 | else if (!strcmp("fade", animation)) |
| 523 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 524 | else if (!strcmp("dim-layer", animation)) |
| 525 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 526 | else |
| 527 | return ANIMATION_NONE; |
| 528 | } |
| 529 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 530 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 531 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 532 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 533 | struct weston_config_section *section; |
| 534 | int duration; |
| 535 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 536 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 537 | section = weston_config_get_section(shell->compositor->config, |
| 538 | "screensaver", NULL, NULL); |
| 539 | weston_config_section_get_string(section, |
| 540 | "path", &shell->screensaver.path, NULL); |
| 541 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 542 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 543 | |
| 544 | section = weston_config_get_section(shell->compositor->config, |
| 545 | "shell", NULL, NULL); |
| 546 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 547 | "client", &s, LIBEXECDIR "/weston-desktop-shell"); |
| 548 | shell->client = s; |
| 549 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 550 | "binding-modifier", &s, "super"); |
| 551 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 552 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 553 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 554 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 555 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 556 | weston_config_section_get_string(section, |
| 557 | "startup-animation", &s, "fade"); |
| 558 | shell->startup_animation_type = get_animation_type(s); |
| 559 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 560 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 561 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 562 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 563 | shell->focus_animation_type = get_animation_type(s); |
| 564 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 565 | weston_config_section_get_uint(section, "num-workspaces", |
| 566 | &shell->workspaces.num, |
| 567 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 568 | } |
| 569 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 570 | static struct weston_output * |
| 571 | get_default_output(struct weston_compositor *compositor) |
| 572 | { |
| 573 | return container_of(compositor->output_list.next, |
| 574 | struct weston_output, link); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | /* no-op func for checking focus surface */ |
| 579 | static void |
| 580 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, |
| 581 | int32_t width, int32_t height) |
| 582 | { |
| 583 | } |
| 584 | |
| 585 | static struct focus_surface * |
| 586 | get_focus_surface(struct weston_surface *surface) |
| 587 | { |
| 588 | if (surface->configure == focus_surface_configure) |
| 589 | return surface->configure_private; |
| 590 | else |
| 591 | return NULL; |
| 592 | } |
| 593 | |
| 594 | static bool |
| 595 | is_focus_surface (struct weston_surface *es) |
| 596 | { |
| 597 | return (es->configure == focus_surface_configure); |
| 598 | } |
| 599 | |
| 600 | static bool |
| 601 | is_focus_view (struct weston_view *view) |
| 602 | { |
| 603 | return is_focus_surface (view->surface); |
| 604 | } |
| 605 | |
| 606 | static struct focus_surface * |
| 607 | create_focus_surface(struct weston_compositor *ec, |
| 608 | struct weston_output *output) |
| 609 | { |
| 610 | struct focus_surface *fsurf = NULL; |
| 611 | struct weston_surface *surface = NULL; |
| 612 | |
| 613 | fsurf = malloc(sizeof *fsurf); |
| 614 | if (!fsurf) |
| 615 | return NULL; |
| 616 | |
| 617 | fsurf->surface = weston_surface_create(ec); |
| 618 | surface = fsurf->surface; |
| 619 | if (surface == NULL) { |
| 620 | free(fsurf); |
| 621 | return NULL; |
| 622 | } |
| 623 | |
| 624 | surface->configure = focus_surface_configure; |
| 625 | surface->output = output; |
| 626 | surface->configure_private = fsurf; |
| 627 | |
| 628 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 629 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 630 | |
| 631 | weston_view_configure(fsurf->view, output->x, output->y, |
| 632 | output->width, output->height); |
| 633 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 634 | pixman_region32_fini(&surface->opaque); |
| 635 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 636 | output->width, output->height); |
| 637 | pixman_region32_fini(&surface->input); |
| 638 | pixman_region32_init(&surface->input); |
| 639 | |
| 640 | wl_list_init(&fsurf->workspace_transform.link); |
| 641 | |
| 642 | return fsurf; |
| 643 | } |
| 644 | |
| 645 | static void |
| 646 | focus_surface_destroy(struct focus_surface *fsurf) |
| 647 | { |
| 648 | weston_surface_destroy(fsurf->surface); |
| 649 | free(fsurf); |
| 650 | } |
| 651 | |
| 652 | static void |
| 653 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 654 | { |
| 655 | struct workspace *ws = data; |
| 656 | |
| 657 | ws->focus_animation = NULL; |
| 658 | } |
| 659 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 660 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 661 | focus_state_destroy(struct focus_state *state) |
| 662 | { |
| 663 | wl_list_remove(&state->seat_destroy_listener.link); |
| 664 | wl_list_remove(&state->surface_destroy_listener.link); |
| 665 | free(state); |
| 666 | } |
| 667 | |
| 668 | static void |
| 669 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 670 | { |
| 671 | struct focus_state *state = container_of(listener, |
| 672 | struct focus_state, |
| 673 | seat_destroy_listener); |
| 674 | |
| 675 | wl_list_remove(&state->link); |
| 676 | focus_state_destroy(state); |
| 677 | } |
| 678 | |
| 679 | static void |
| 680 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 681 | { |
| 682 | struct focus_state *state = container_of(listener, |
| 683 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 684 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 685 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 686 | struct weston_surface *main_surface, *next; |
| 687 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 688 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 689 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 690 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 691 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 692 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 693 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 694 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 695 | if (is_focus_view(view)) |
| 696 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 697 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 698 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 699 | break; |
| 700 | } |
| 701 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 702 | /* if the focus was a sub-surface, activate its main surface */ |
| 703 | if (main_surface != state->keyboard_focus) |
| 704 | next = main_surface; |
| 705 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 706 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 707 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 708 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 709 | activate(shell, next, state->seat); |
| 710 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 711 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 712 | if (state->ws->focus_animation) |
| 713 | weston_view_animation_destroy(state->ws->focus_animation); |
| 714 | |
| 715 | state->ws->focus_animation = weston_fade_run( |
| 716 | state->ws->fsurf_front->view, |
| 717 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 718 | focus_animation_done, state->ws); |
| 719 | } |
| 720 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 721 | wl_list_remove(&state->link); |
| 722 | focus_state_destroy(state); |
| 723 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 727 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 728 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 729 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 730 | |
| 731 | state = malloc(sizeof *state); |
| 732 | if (state == NULL) |
| 733 | return NULL; |
| 734 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 735 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 736 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 737 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 738 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 739 | |
| 740 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 741 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 742 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 743 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 744 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 745 | |
| 746 | return state; |
| 747 | } |
| 748 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 749 | static struct focus_state * |
| 750 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 751 | { |
| 752 | struct workspace *ws = get_current_workspace(shell); |
| 753 | struct focus_state *state; |
| 754 | |
| 755 | wl_list_for_each(state, &ws->focus_list, link) |
| 756 | if (state->seat == seat) |
| 757 | break; |
| 758 | |
| 759 | if (&state->link == &ws->focus_list) |
| 760 | state = focus_state_create(seat, ws); |
| 761 | |
| 762 | return state; |
| 763 | } |
| 764 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 765 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 766 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 767 | { |
| 768 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 769 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 770 | |
| 771 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 772 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 773 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 774 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
| 778 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 779 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 780 | struct weston_seat *seat) |
| 781 | { |
| 782 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 783 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 784 | |
| 785 | wl_list_for_each(state, &ws->focus_list, link) { |
| 786 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 787 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 788 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 789 | return; |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | static void |
| 795 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 796 | struct weston_surface *surface) |
| 797 | { |
| 798 | struct focus_state *state; |
| 799 | |
| 800 | wl_list_for_each(state, &ws->focus_list, link) |
| 801 | if (state->keyboard_focus == surface) |
| 802 | state->keyboard_focus = NULL; |
| 803 | } |
| 804 | |
| 805 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 806 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 807 | struct weston_view *from, struct weston_view *to) |
| 808 | { |
| 809 | struct weston_output *output; |
| 810 | bool focus_surface_created = false; |
| 811 | |
| 812 | /* FIXME: Only support dim animation using two layers */ |
| 813 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 814 | return; |
| 815 | |
| 816 | output = get_default_output(shell->compositor); |
| 817 | if (ws->fsurf_front == NULL && (from || to)) { |
| 818 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 819 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 820 | ws->fsurf_front->view->alpha = 0.0; |
| 821 | ws->fsurf_back->view->alpha = 0.0; |
| 822 | focus_surface_created = true; |
| 823 | } else { |
| 824 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 825 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 826 | } |
| 827 | |
| 828 | if (ws->focus_animation) { |
| 829 | weston_view_animation_destroy(ws->focus_animation); |
| 830 | ws->focus_animation = NULL; |
| 831 | } |
| 832 | |
| 833 | if (to) |
| 834 | wl_list_insert(&to->layer_link, |
| 835 | &ws->fsurf_front->view->layer_link); |
| 836 | else if (from) |
| 837 | wl_list_insert(&ws->layer.view_list, |
| 838 | &ws->fsurf_front->view->layer_link); |
| 839 | |
| 840 | if (focus_surface_created) { |
| 841 | ws->focus_animation = weston_fade_run( |
| 842 | ws->fsurf_front->view, |
| 843 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 844 | focus_animation_done, ws); |
| 845 | } else if (from) { |
| 846 | wl_list_insert(&from->layer_link, |
| 847 | &ws->fsurf_back->view->layer_link); |
| 848 | ws->focus_animation = weston_stable_fade_run( |
| 849 | ws->fsurf_front->view, 0.0, |
| 850 | ws->fsurf_back->view, 0.6, |
| 851 | focus_animation_done, ws); |
| 852 | } else if (to) { |
| 853 | wl_list_insert(&ws->layer.view_list, |
| 854 | &ws->fsurf_back->view->layer_link); |
| 855 | ws->focus_animation = weston_stable_fade_run( |
| 856 | ws->fsurf_front->view, 0.0, |
| 857 | ws->fsurf_back->view, 0.6, |
| 858 | focus_animation_done, ws); |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 863 | workspace_destroy(struct workspace *ws) |
| 864 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 865 | struct focus_state *state, *next; |
| 866 | |
| 867 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 868 | focus_state_destroy(state); |
| 869 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 870 | if (ws->fsurf_front) |
| 871 | focus_surface_destroy(ws->fsurf_front); |
| 872 | if (ws->fsurf_back) |
| 873 | focus_surface_destroy(ws->fsurf_back); |
| 874 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 875 | free(ws); |
| 876 | } |
| 877 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 878 | static void |
| 879 | seat_destroyed(struct wl_listener *listener, void *data) |
| 880 | { |
| 881 | struct weston_seat *seat = data; |
| 882 | struct focus_state *state, *next; |
| 883 | struct workspace *ws = container_of(listener, |
| 884 | struct workspace, |
| 885 | seat_destroyed_listener); |
| 886 | |
| 887 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 888 | if (state->seat == seat) |
| 889 | wl_list_remove(&state->link); |
| 890 | } |
| 891 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 892 | static struct workspace * |
| 893 | workspace_create(void) |
| 894 | { |
| 895 | struct workspace *ws = malloc(sizeof *ws); |
| 896 | if (ws == NULL) |
| 897 | return NULL; |
| 898 | |
| 899 | weston_layer_init(&ws->layer, NULL); |
| 900 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 901 | wl_list_init(&ws->focus_list); |
| 902 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 903 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 904 | ws->fsurf_front = NULL; |
| 905 | ws->fsurf_back = NULL; |
| 906 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 907 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 908 | return ws; |
| 909 | } |
| 910 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 911 | static int |
| 912 | workspace_is_empty(struct workspace *ws) |
| 913 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 914 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 915 | } |
| 916 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 917 | static struct workspace * |
| 918 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 919 | { |
| 920 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 921 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 922 | pws += index; |
| 923 | return *pws; |
| 924 | } |
| 925 | |
| 926 | static struct workspace * |
| 927 | get_current_workspace(struct desktop_shell *shell) |
| 928 | { |
| 929 | return get_workspace(shell, shell->workspaces.current); |
| 930 | } |
| 931 | |
| 932 | static void |
| 933 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 934 | { |
| 935 | struct workspace *ws; |
| 936 | |
| 937 | ws = get_workspace(shell, index); |
| 938 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 939 | |
| 940 | shell->workspaces.current = index; |
| 941 | } |
| 942 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 943 | static unsigned int |
| 944 | get_output_height(struct weston_output *output) |
| 945 | { |
| 946 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 947 | } |
| 948 | |
| 949 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 950 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 951 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 952 | struct weston_transform *transform; |
| 953 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 954 | if (is_focus_view(view)) { |
| 955 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 956 | transform = &fsurf->workspace_transform; |
| 957 | } else { |
| 958 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 959 | transform = &shsurf->workspace_transform; |
| 960 | } |
| 961 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 962 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 963 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 964 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 965 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 966 | weston_matrix_init(&transform->matrix); |
| 967 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 968 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 969 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static void |
| 973 | workspace_translate_out(struct workspace *ws, double fraction) |
| 974 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 975 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 976 | unsigned int height; |
| 977 | double d; |
| 978 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 979 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 980 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 981 | d = height * fraction; |
| 982 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 983 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | |
| 987 | static void |
| 988 | workspace_translate_in(struct workspace *ws, double fraction) |
| 989 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 990 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 991 | unsigned int height; |
| 992 | double d; |
| 993 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 994 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 995 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 996 | |
| 997 | if (fraction > 0) |
| 998 | d = -(height - height * fraction); |
| 999 | else |
| 1000 | d = height + height * fraction; |
| 1001 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1002 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1007 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1008 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1009 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1010 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1011 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1012 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1013 | shell->workspaces.current, |
| 1014 | shell->workspaces.num); |
| 1015 | } |
| 1016 | |
| 1017 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1018 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1019 | unsigned int index, |
| 1020 | struct workspace *from, |
| 1021 | struct workspace *to) |
| 1022 | { |
| 1023 | shell->workspaces.current = index; |
| 1024 | |
| 1025 | shell->workspaces.anim_to = to; |
| 1026 | shell->workspaces.anim_from = from; |
| 1027 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1028 | shell->workspaces.anim_timestamp = 0; |
| 1029 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1030 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static void |
| 1034 | workspace_deactivate_transforms(struct workspace *ws) |
| 1035 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1036 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1037 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1038 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1039 | 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] | 1040 | if (is_focus_view(view)) { |
| 1041 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1042 | transform = &fsurf->workspace_transform; |
| 1043 | } else { |
| 1044 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1045 | transform = &shsurf->workspace_transform; |
| 1046 | } |
| 1047 | |
| 1048 | if (!wl_list_empty(&transform->link)) { |
| 1049 | wl_list_remove(&transform->link); |
| 1050 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1051 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1052 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | static void |
| 1057 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1058 | struct workspace *from, |
| 1059 | struct workspace *to) |
| 1060 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1061 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1062 | |
| 1063 | wl_list_remove(&shell->workspaces.animation.link); |
| 1064 | workspace_deactivate_transforms(from); |
| 1065 | workspace_deactivate_transforms(to); |
| 1066 | shell->workspaces.anim_to = NULL; |
| 1067 | |
| 1068 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1069 | } |
| 1070 | |
| 1071 | static void |
| 1072 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1073 | struct weston_output *output, uint32_t msecs) |
| 1074 | { |
| 1075 | struct desktop_shell *shell = |
| 1076 | container_of(animation, struct desktop_shell, |
| 1077 | workspaces.animation); |
| 1078 | struct workspace *from = shell->workspaces.anim_from; |
| 1079 | struct workspace *to = shell->workspaces.anim_to; |
| 1080 | uint32_t t; |
| 1081 | double x, y; |
| 1082 | |
| 1083 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1084 | finish_workspace_change_animation(shell, from, to); |
| 1085 | return; |
| 1086 | } |
| 1087 | |
| 1088 | if (shell->workspaces.anim_timestamp == 0) { |
| 1089 | if (shell->workspaces.anim_current == 0.0) |
| 1090 | shell->workspaces.anim_timestamp = msecs; |
| 1091 | else |
| 1092 | shell->workspaces.anim_timestamp = |
| 1093 | msecs - |
| 1094 | /* Invers of movement function 'y' below. */ |
| 1095 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1096 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1097 | M_2_PI); |
| 1098 | } |
| 1099 | |
| 1100 | t = msecs - shell->workspaces.anim_timestamp; |
| 1101 | |
| 1102 | /* |
| 1103 | * x = [0, π/2] |
| 1104 | * y(x) = sin(x) |
| 1105 | */ |
| 1106 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1107 | y = sin(x); |
| 1108 | |
| 1109 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1110 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1111 | |
| 1112 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1113 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1114 | shell->workspaces.anim_current = y; |
| 1115 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1116 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1117 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1118 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1119 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | static void |
| 1123 | animate_workspace_change(struct desktop_shell *shell, |
| 1124 | unsigned int index, |
| 1125 | struct workspace *from, |
| 1126 | struct workspace *to) |
| 1127 | { |
| 1128 | struct weston_output *output; |
| 1129 | |
| 1130 | int dir; |
| 1131 | |
| 1132 | if (index > shell->workspaces.current) |
| 1133 | dir = -1; |
| 1134 | else |
| 1135 | dir = 1; |
| 1136 | |
| 1137 | shell->workspaces.current = index; |
| 1138 | |
| 1139 | shell->workspaces.anim_dir = dir; |
| 1140 | shell->workspaces.anim_from = from; |
| 1141 | shell->workspaces.anim_to = to; |
| 1142 | shell->workspaces.anim_current = 0.0; |
| 1143 | shell->workspaces.anim_timestamp = 0; |
| 1144 | |
| 1145 | output = container_of(shell->compositor->output_list.next, |
| 1146 | struct weston_output, link); |
| 1147 | wl_list_insert(&output->animation_list, |
| 1148 | &shell->workspaces.animation.link); |
| 1149 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1150 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1151 | |
| 1152 | workspace_translate_in(to, 0); |
| 1153 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1154 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1155 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1156 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1157 | } |
| 1158 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1159 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1160 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1161 | struct workspace *from, struct workspace *to) |
| 1162 | { |
| 1163 | shell->workspaces.current = index; |
| 1164 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1165 | wl_list_remove(&from->layer.link); |
| 1166 | } |
| 1167 | |
| 1168 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1169 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1170 | { |
| 1171 | struct workspace *from; |
| 1172 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1173 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1174 | |
| 1175 | if (index == shell->workspaces.current) |
| 1176 | return; |
| 1177 | |
| 1178 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1179 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1180 | return; |
| 1181 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1182 | from = get_current_workspace(shell); |
| 1183 | to = get_workspace(shell, index); |
| 1184 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1185 | if (shell->workspaces.anim_from == to && |
| 1186 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1187 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1188 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1189 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1190 | return; |
| 1191 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1192 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1193 | if (shell->workspaces.anim_to != NULL) |
| 1194 | finish_workspace_change_animation(shell, |
| 1195 | shell->workspaces.anim_from, |
| 1196 | shell->workspaces.anim_to); |
| 1197 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1198 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1199 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1200 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1201 | wl_list_for_each(state, &from->focus_list, link) |
| 1202 | if (state->keyboard_focus) |
| 1203 | animate_focus_change(shell, from, |
| 1204 | get_default_view(state->keyboard_focus), NULL); |
| 1205 | |
| 1206 | wl_list_for_each(state, &to->focus_list, link) |
| 1207 | if (state->keyboard_focus) |
| 1208 | animate_focus_change(shell, to, |
| 1209 | NULL, get_default_view(state->keyboard_focus)); |
| 1210 | } |
| 1211 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1212 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1213 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1214 | else |
| 1215 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1216 | |
| 1217 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1218 | } |
| 1219 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1220 | static bool |
| 1221 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1222 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1223 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1224 | struct wl_list *e; |
| 1225 | |
| 1226 | if (wl_list_empty(list)) |
| 1227 | return false; |
| 1228 | |
| 1229 | e = list->next; |
| 1230 | |
| 1231 | if (e->next != list) |
| 1232 | return false; |
| 1233 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1234 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1238 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1239 | struct shell_surface *shsurf, |
| 1240 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1241 | { |
| 1242 | struct workspace *from; |
| 1243 | struct workspace *to; |
| 1244 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1245 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1246 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1247 | |
| 1248 | if (workspace == shell->workspaces.current) |
| 1249 | return; |
| 1250 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1251 | view = get_default_view(shsurf->surface); |
| 1252 | if (!view) |
| 1253 | return; |
| 1254 | |
| 1255 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1256 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1257 | if (workspace >= shell->workspaces.num) |
| 1258 | workspace = shell->workspaces.num - 1; |
| 1259 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1260 | from = get_current_workspace(shell); |
| 1261 | to = get_workspace(shell, workspace); |
| 1262 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1263 | wl_list_remove(&view->layer_link); |
| 1264 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1265 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1266 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1267 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1268 | if (!seat->keyboard) |
| 1269 | continue; |
| 1270 | |
| 1271 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1272 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1273 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1274 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1275 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1276 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1280 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1281 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1282 | unsigned int index) |
| 1283 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1284 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1285 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1286 | struct shell_surface *shsurf; |
| 1287 | struct workspace *from; |
| 1288 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1289 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1290 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1291 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1292 | view = get_default_view(surface); |
| 1293 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1294 | index == shell->workspaces.current || |
| 1295 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1296 | return; |
| 1297 | |
| 1298 | from = get_current_workspace(shell); |
| 1299 | to = get_workspace(shell, index); |
| 1300 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1301 | wl_list_remove(&view->layer_link); |
| 1302 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1303 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1304 | shsurf = get_shell_surface(surface); |
| 1305 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1306 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1307 | drop_focus_state(shell, from, surface); |
| 1308 | |
| 1309 | if (shell->workspaces.anim_from == to && |
| 1310 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1311 | wl_list_remove(&to->layer.link); |
| 1312 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1313 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1314 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1315 | broadcast_current_workspace_state(shell); |
| 1316 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1317 | return; |
| 1318 | } |
| 1319 | |
| 1320 | if (shell->workspaces.anim_to != NULL) |
| 1321 | finish_workspace_change_animation(shell, |
| 1322 | shell->workspaces.anim_from, |
| 1323 | shell->workspaces.anim_to); |
| 1324 | |
| 1325 | if (workspace_is_empty(from) && |
| 1326 | workspace_has_only(to, surface)) |
| 1327 | update_workspace(shell, index, from, to); |
| 1328 | else { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1329 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 1330 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1331 | &shsurf->workspace_transform.link); |
| 1332 | |
| 1333 | animate_workspace_change(shell, index, from, to); |
| 1334 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1335 | |
| 1336 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1337 | |
| 1338 | state = ensure_focus_state(shell, seat); |
| 1339 | if (state != NULL) |
| 1340 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | static void |
| 1344 | workspace_manager_move_surface(struct wl_client *client, |
| 1345 | struct wl_resource *resource, |
| 1346 | struct wl_resource *surface_resource, |
| 1347 | uint32_t workspace) |
| 1348 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1349 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1350 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1351 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1352 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1353 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1354 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1355 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1356 | shell_surface = get_shell_surface(main_surface); |
| 1357 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1358 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1359 | |
| 1360 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1364 | workspace_manager_move_surface, |
| 1365 | }; |
| 1366 | |
| 1367 | static void |
| 1368 | unbind_resource(struct wl_resource *resource) |
| 1369 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1370 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | static void |
| 1374 | bind_workspace_manager(struct wl_client *client, |
| 1375 | void *data, uint32_t version, uint32_t id) |
| 1376 | { |
| 1377 | struct desktop_shell *shell = data; |
| 1378 | struct wl_resource *resource; |
| 1379 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1380 | resource = wl_resource_create(client, |
| 1381 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1382 | |
| 1383 | if (resource == NULL) { |
| 1384 | weston_log("couldn't add workspace manager object"); |
| 1385 | return; |
| 1386 | } |
| 1387 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1388 | wl_resource_set_implementation(resource, |
| 1389 | &workspace_manager_implementation, |
| 1390 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1391 | wl_list_insert(&shell->workspaces.client_list, |
| 1392 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1393 | |
| 1394 | workspace_manager_send_state(resource, |
| 1395 | shell->workspaces.current, |
| 1396 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1399 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1400 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1401 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1402 | { |
| 1403 | } |
| 1404 | |
| 1405 | static void |
| 1406 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1407 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1408 | struct weston_touch_move_grab *move = |
| 1409 | (struct weston_touch_move_grab *) container_of( |
| 1410 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1411 | |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1412 | if (grab->touch->seat->num_tp == 0) { |
| 1413 | shell_touch_grab_end(&move->base); |
| 1414 | free(move); |
| 1415 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static void |
| 1419 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1420 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1421 | { |
| 1422 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1423 | struct shell_surface *shsurf = move->base.shsurf; |
| 1424 | struct weston_surface *es; |
| 1425 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1426 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1427 | |
| 1428 | if (!shsurf) |
| 1429 | return; |
| 1430 | |
| 1431 | es = shsurf->surface; |
| 1432 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1433 | weston_view_configure(shsurf->view, dx, dy, |
| 1434 | shsurf->view->geometry.width, |
| 1435 | shsurf->view->geometry.height); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1436 | |
| 1437 | weston_compositor_schedule_repaint(es->compositor); |
| 1438 | } |
| 1439 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1440 | static void |
| 1441 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1442 | { |
| 1443 | struct weston_touch_move_grab *move = |
| 1444 | (struct weston_touch_move_grab *) container_of( |
| 1445 | grab, struct shell_touch_grab, grab); |
| 1446 | |
| 1447 | shell_touch_grab_end(&move->base); |
| 1448 | free(move); |
| 1449 | } |
| 1450 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1451 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1452 | touch_move_grab_down, |
| 1453 | touch_move_grab_up, |
| 1454 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1455 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1456 | }; |
| 1457 | |
| 1458 | static int |
| 1459 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1460 | { |
| 1461 | struct weston_touch_move_grab *move; |
| 1462 | |
| 1463 | if (!shsurf) |
| 1464 | return -1; |
| 1465 | |
| 1466 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1467 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1468 | if (shsurf->grabbed) |
| 1469 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1470 | |
| 1471 | move = malloc(sizeof *move); |
| 1472 | if (!move) |
| 1473 | return -1; |
| 1474 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1475 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1476 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1477 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1478 | seat->touch->grab_y; |
| 1479 | |
| 1480 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1481 | seat->touch); |
| 1482 | |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
| 1486 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1487 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1488 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1492 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1493 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1494 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1495 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1496 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1497 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1498 | int dx, dy; |
| 1499 | |
| 1500 | weston_pointer_move(pointer, x, y); |
| 1501 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1502 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1503 | |
| 1504 | if (!shsurf) |
| 1505 | return; |
| 1506 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1507 | weston_view_configure(shsurf->view, dx, dy, |
| 1508 | shsurf->view->geometry.width, |
| 1509 | shsurf->view->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1510 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1511 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1515 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1516 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1517 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1518 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1519 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1520 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1521 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1522 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1523 | if (pointer->button_count == 0 && |
| 1524 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1525 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1526 | free(grab); |
| 1527 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1528 | } |
| 1529 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1530 | static void |
| 1531 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1532 | { |
| 1533 | struct shell_grab *shell_grab = |
| 1534 | container_of(grab, struct shell_grab, grab); |
| 1535 | |
| 1536 | shell_grab_end(shell_grab); |
| 1537 | free(grab); |
| 1538 | } |
| 1539 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1540 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1541 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1542 | move_grab_motion, |
| 1543 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1544 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1545 | }; |
| 1546 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1547 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1548 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1549 | { |
| 1550 | struct weston_move_grab *move; |
| 1551 | |
| 1552 | if (!shsurf) |
| 1553 | return -1; |
| 1554 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1555 | if (shsurf->grabbed) |
| 1556 | return 0; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1557 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1558 | return 0; |
| 1559 | |
| 1560 | move = malloc(sizeof *move); |
| 1561 | if (!move) |
| 1562 | return -1; |
| 1563 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1564 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1565 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1566 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1567 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1568 | |
| 1569 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1570 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1571 | |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
| 1575 | static void |
| 1576 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1577 | struct wl_resource *seat_resource, uint32_t serial) |
| 1578 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1579 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1580 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1581 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1582 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1583 | if (seat->pointer && |
| 1584 | seat->pointer->button_count > 0 && |
| 1585 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1586 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1587 | if ((surface == shsurf->surface) && |
| 1588 | (surface_move(shsurf, seat) < 0)) |
| 1589 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1590 | } else if (seat->touch && |
| 1591 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1592 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1593 | if ((surface == shsurf->surface) && |
| 1594 | (surface_touch_move(shsurf, seat) < 0)) |
| 1595 | wl_resource_post_no_memory(resource); |
| 1596 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | struct weston_resize_grab { |
| 1600 | struct shell_grab base; |
| 1601 | uint32_t edges; |
| 1602 | int32_t width, height; |
| 1603 | }; |
| 1604 | |
| 1605 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1606 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1607 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1608 | { |
| 1609 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1610 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1611 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1612 | int32_t width, height; |
| 1613 | wl_fixed_t from_x, from_y; |
| 1614 | wl_fixed_t to_x, to_y; |
| 1615 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1616 | weston_pointer_move(pointer, x, y); |
| 1617 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1618 | if (!shsurf) |
| 1619 | return; |
| 1620 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1621 | weston_view_from_global_fixed(shsurf->view, |
| 1622 | pointer->grab_x, pointer->grab_y, |
| 1623 | &from_x, &from_y); |
| 1624 | weston_view_from_global_fixed(shsurf->view, |
| 1625 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1626 | |
| 1627 | width = resize->width; |
| 1628 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1629 | width += wl_fixed_to_int(from_x - to_x); |
| 1630 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1631 | width += wl_fixed_to_int(to_x - from_x); |
| 1632 | } |
| 1633 | |
| 1634 | height = resize->height; |
| 1635 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1636 | height += wl_fixed_to_int(from_y - to_y); |
| 1637 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1638 | height += wl_fixed_to_int(to_y - from_y); |
| 1639 | } |
| 1640 | |
| 1641 | shsurf->client->send_configure(shsurf->surface, |
| 1642 | resize->edges, width, height); |
| 1643 | } |
| 1644 | |
| 1645 | static void |
| 1646 | send_configure(struct weston_surface *surface, |
| 1647 | uint32_t edges, int32_t width, int32_t height) |
| 1648 | { |
| 1649 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1650 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1651 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1652 | edges, width, height); |
| 1653 | } |
| 1654 | |
| 1655 | static const struct weston_shell_client shell_client = { |
| 1656 | send_configure |
| 1657 | }; |
| 1658 | |
| 1659 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1660 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1661 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1662 | { |
| 1663 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1664 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1665 | enum wl_pointer_button_state state = state_w; |
| 1666 | |
| 1667 | if (pointer->button_count == 0 && |
| 1668 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1669 | shell_grab_end(&resize->base); |
| 1670 | free(grab); |
| 1671 | } |
| 1672 | } |
| 1673 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1674 | static void |
| 1675 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1676 | { |
| 1677 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1678 | |
| 1679 | shell_grab_end(&resize->base); |
| 1680 | free(grab); |
| 1681 | } |
| 1682 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1683 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1684 | noop_grab_focus, |
| 1685 | resize_grab_motion, |
| 1686 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1687 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1688 | }; |
| 1689 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1690 | /* |
| 1691 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1692 | * in the surface coordinates system. */ |
| 1693 | static void |
| 1694 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1695 | int32_t *y, int32_t *w, int32_t *h) { |
| 1696 | pixman_region32_t region; |
| 1697 | pixman_box32_t *box; |
| 1698 | struct weston_subsurface *subsurface; |
| 1699 | |
| 1700 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1701 | surface->width, |
| 1702 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1703 | |
| 1704 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1705 | pixman_region32_union_rect(®ion, ®ion, |
| 1706 | subsurface->position.x, |
| 1707 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1708 | subsurface->surface->width, |
| 1709 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | box = pixman_region32_extents(®ion); |
| 1713 | if (x) |
| 1714 | *x = box->x1; |
| 1715 | if (y) |
| 1716 | *y = box->y1; |
| 1717 | if (w) |
| 1718 | *w = box->x2 - box->x1; |
| 1719 | if (h) |
| 1720 | *h = box->y2 - box->y1; |
| 1721 | |
| 1722 | pixman_region32_fini(®ion); |
| 1723 | } |
| 1724 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1725 | static int |
| 1726 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1727 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1728 | { |
| 1729 | struct weston_resize_grab *resize; |
| 1730 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1731 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1732 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1733 | return 0; |
| 1734 | |
| 1735 | if (edges == 0 || edges > 15 || |
| 1736 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1737 | return 0; |
| 1738 | |
| 1739 | resize = malloc(sizeof *resize); |
| 1740 | if (!resize) |
| 1741 | return -1; |
| 1742 | |
| 1743 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1744 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1745 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1746 | |
| 1747 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1748 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1749 | |
| 1750 | return 0; |
| 1751 | } |
| 1752 | |
| 1753 | static void |
| 1754 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1755 | struct wl_resource *seat_resource, uint32_t serial, |
| 1756 | uint32_t edges) |
| 1757 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1758 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1759 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1760 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1761 | |
| 1762 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1763 | return; |
| 1764 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1765 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1766 | if (seat->pointer->button_count == 0 || |
| 1767 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1768 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1769 | return; |
| 1770 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1771 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1772 | wl_resource_post_no_memory(resource); |
| 1773 | } |
| 1774 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1775 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1776 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1777 | |
| 1778 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1779 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1780 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1781 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1782 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1783 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1784 | wl_fixed_t sx, sy; |
| 1785 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1786 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1787 | pointer->x, pointer->y, |
| 1788 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1789 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1790 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1791 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1795 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1796 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1797 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1798 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1799 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1800 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1801 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1802 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1803 | uint32_t time, uint32_t button, uint32_t state) |
| 1804 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1805 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1806 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1807 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1808 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1809 | if (shsurf && button == BTN_LEFT && state) { |
| 1810 | activate(shsurf->shell, shsurf->surface, seat); |
| 1811 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1812 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1813 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1814 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1815 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1816 | } |
| 1817 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1818 | static void |
| 1819 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1820 | { |
| 1821 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1822 | |
| 1823 | shell_grab_end(grab); |
| 1824 | free(grab); |
| 1825 | } |
| 1826 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1827 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1828 | busy_cursor_grab_focus, |
| 1829 | busy_cursor_grab_motion, |
| 1830 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1831 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1832 | }; |
| 1833 | |
| 1834 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1835 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1836 | { |
| 1837 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1838 | |
| 1839 | grab = malloc(sizeof *grab); |
| 1840 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1841 | return; |
| 1842 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1843 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1844 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1845 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1846 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1847 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1848 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1849 | { |
| 1850 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1851 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1852 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1853 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1854 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1855 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1856 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1857 | } |
| 1858 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1859 | static void |
| 1860 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1861 | { |
| 1862 | if (!shsurf || !shsurf->ping_timer) |
| 1863 | return; |
| 1864 | |
| 1865 | if (shsurf->ping_timer->source) |
| 1866 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1867 | |
| 1868 | free(shsurf->ping_timer); |
| 1869 | shsurf->ping_timer = NULL; |
| 1870 | } |
| 1871 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1872 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1873 | ping_timeout_handler(void *data) |
| 1874 | { |
| 1875 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1876 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1877 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1878 | /* Client is not responding */ |
| 1879 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1880 | |
| 1881 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1882 | if (seat->pointer->focus && |
| 1883 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1884 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1885 | |
| 1886 | return 1; |
| 1887 | } |
| 1888 | |
| 1889 | static void |
| 1890 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1891 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1892 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1893 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1894 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1895 | |
| 1896 | if (!shsurf) |
| 1897 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1898 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1899 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1900 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1901 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1902 | return; |
| 1903 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1904 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1905 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1906 | if (!shsurf->ping_timer) |
| 1907 | return; |
| 1908 | |
| 1909 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1910 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1911 | shsurf->ping_timer->source = |
| 1912 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1913 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1914 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1915 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1920 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1921 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1922 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1923 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1924 | struct weston_compositor *compositor; |
| 1925 | struct shell_surface *shsurf; |
| 1926 | uint32_t serial; |
| 1927 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1928 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1929 | return; |
| 1930 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1931 | compositor = view->surface->compositor; |
| 1932 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1933 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1934 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1935 | set_busy_cursor(shsurf, pointer); |
| 1936 | } else { |
| 1937 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1938 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1943 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1944 | { |
| 1945 | struct wl_listener *listener; |
| 1946 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1947 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1948 | return; |
| 1949 | |
| 1950 | listener = malloc(sizeof *listener); |
| 1951 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1952 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1956 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1957 | uint32_t serial) |
| 1958 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1959 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1960 | struct weston_seat *seat; |
| 1961 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1962 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1963 | if (shsurf->ping_timer == NULL) |
| 1964 | /* Just ignore unsolicited pong. */ |
| 1965 | return; |
| 1966 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1967 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1968 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1969 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1970 | if(seat->pointer) |
| 1971 | end_busy_cursor(shsurf, seat->pointer); |
| 1972 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1973 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1974 | } |
| 1975 | } |
| 1976 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1977 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1978 | set_title(struct shell_surface *shsurf, const char *title) |
| 1979 | { |
| 1980 | free(shsurf->title); |
| 1981 | shsurf->title = strdup(title); |
| 1982 | } |
| 1983 | |
| 1984 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1985 | shell_surface_set_title(struct wl_client *client, |
| 1986 | struct wl_resource *resource, const char *title) |
| 1987 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1988 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1989 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1990 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | static void |
| 1994 | shell_surface_set_class(struct wl_client *client, |
| 1995 | struct wl_resource *resource, const char *class) |
| 1996 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1997 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1998 | |
| 1999 | free(shsurf->class); |
| 2000 | shsurf->class = strdup(class); |
| 2001 | } |
| 2002 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2003 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2004 | restore_output_mode(struct weston_output *output) |
| 2005 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2006 | if (output->current_mode != output->original_mode || |
| 2007 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2008 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2009 | output->original_mode, |
| 2010 | output->original_scale, |
| 2011 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | static void |
| 2015 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2016 | { |
| 2017 | struct weston_output *output; |
| 2018 | |
| 2019 | wl_list_for_each(output, &compositor->output_list, link) |
| 2020 | restore_output_mode(output); |
| 2021 | } |
| 2022 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2023 | static int |
| 2024 | get_output_panel_height(struct desktop_shell *shell, |
| 2025 | struct weston_output *output) |
| 2026 | { |
| 2027 | struct weston_view *view; |
| 2028 | int panel_height = 0; |
| 2029 | |
| 2030 | if (!output) |
| 2031 | return 0; |
| 2032 | |
| 2033 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2034 | if (view->surface->output == output) { |
| 2035 | panel_height = view->geometry.height; |
| 2036 | break; |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | return panel_height; |
| 2041 | } |
| 2042 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2043 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2044 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2045 | struct weston_output *output) |
| 2046 | { |
| 2047 | struct weston_surface *es = shsurf->surface; |
| 2048 | |
| 2049 | /* get the default output, if the client set it as NULL |
| 2050 | check whether the ouput is available */ |
| 2051 | if (output) |
| 2052 | shsurf->output = output; |
| 2053 | else if (es->output) |
| 2054 | shsurf->output = es->output; |
| 2055 | else |
| 2056 | shsurf->output = get_default_output(es->compositor); |
| 2057 | } |
| 2058 | |
| 2059 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2060 | set_toplevel(struct shell_surface *shsurf) |
| 2061 | { |
| 2062 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
| 2063 | } |
| 2064 | |
| 2065 | static void |
| 2066 | shell_surface_set_toplevel(struct wl_client *client, |
| 2067 | struct wl_resource *resource) |
| 2068 | { |
| 2069 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2070 | |
| 2071 | set_toplevel(surface); |
| 2072 | } |
| 2073 | |
| 2074 | static void |
| 2075 | set_transient(struct shell_surface *shsurf, |
| 2076 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2077 | { |
| 2078 | /* assign to parents output */ |
| 2079 | shsurf->parent = parent; |
| 2080 | shsurf->transient.x = x; |
| 2081 | shsurf->transient.y = y; |
| 2082 | shsurf->transient.flags = flags; |
| 2083 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 2084 | } |
| 2085 | |
| 2086 | static void |
| 2087 | shell_surface_set_transient(struct wl_client *client, |
| 2088 | struct wl_resource *resource, |
| 2089 | struct wl_resource *parent_resource, |
| 2090 | int x, int y, uint32_t flags) |
| 2091 | { |
| 2092 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2093 | struct weston_surface *parent = |
| 2094 | wl_resource_get_user_data(parent_resource); |
| 2095 | |
| 2096 | set_transient(shsurf, parent, x, y, flags); |
| 2097 | } |
| 2098 | |
| 2099 | static void |
| 2100 | set_fullscreen(struct shell_surface *shsurf, |
| 2101 | uint32_t method, |
| 2102 | uint32_t framerate, |
| 2103 | struct weston_output *output) |
| 2104 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2105 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2106 | |
| 2107 | shsurf->fullscreen_output = shsurf->output; |
| 2108 | shsurf->fullscreen.type = method; |
| 2109 | shsurf->fullscreen.framerate = framerate; |
| 2110 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
| 2111 | |
| 2112 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2113 | shsurf->output->width, |
| 2114 | shsurf->output->height); |
| 2115 | } |
| 2116 | |
| 2117 | static void |
| 2118 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2119 | { |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2120 | struct workspace *ws; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame^] | 2121 | |
| 2122 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2123 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2124 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2125 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2126 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame^] | 2127 | shsurf->fullscreen_output = NULL; |
| 2128 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2129 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2130 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame^] | 2131 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2132 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2133 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame^] | 2134 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2135 | if (shsurf->fullscreen.black_view) |
| 2136 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2137 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame^] | 2138 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2139 | weston_view_set_position(shsurf->view, |
| 2140 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2141 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2142 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2143 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2144 | shsurf->saved_rotation_valid = false; |
| 2145 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2146 | |
| 2147 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2148 | wl_list_remove(&shsurf->view->layer_link); |
| 2149 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2150 | } |
| 2151 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2152 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2153 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2154 | struct wl_resource *resource, |
| 2155 | uint32_t method, |
| 2156 | uint32_t framerate, |
| 2157 | struct wl_resource *output_resource) |
| 2158 | { |
| 2159 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2160 | struct weston_output *output; |
| 2161 | |
| 2162 | if (output_resource) |
| 2163 | output = wl_resource_get_user_data(output_resource); |
| 2164 | else |
| 2165 | output = NULL; |
| 2166 | |
| 2167 | set_fullscreen(shsurf, method, framerate, output); |
| 2168 | } |
| 2169 | |
| 2170 | static void |
| 2171 | set_popup(struct shell_surface *shsurf, |
| 2172 | struct weston_surface *parent, |
| 2173 | struct weston_seat *seat, |
| 2174 | uint32_t serial, |
| 2175 | int32_t x, |
| 2176 | int32_t y) |
| 2177 | { |
| 2178 | shsurf->type = SHELL_SURFACE_POPUP; |
| 2179 | shsurf->parent = parent; |
| 2180 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2181 | shsurf->popup.serial = serial; |
| 2182 | shsurf->popup.x = x; |
| 2183 | shsurf->popup.y = y; |
| 2184 | } |
| 2185 | |
| 2186 | static void |
| 2187 | shell_surface_set_popup(struct wl_client *client, |
| 2188 | struct wl_resource *resource, |
| 2189 | struct wl_resource *seat_resource, |
| 2190 | uint32_t serial, |
| 2191 | struct wl_resource *parent_resource, |
| 2192 | int32_t x, int32_t y, uint32_t flags) |
| 2193 | { |
| 2194 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2195 | |
| 2196 | set_popup(shsurf, |
| 2197 | wl_resource_get_user_data(parent_resource), |
| 2198 | wl_resource_get_user_data(seat_resource), |
| 2199 | serial, x, y); |
| 2200 | } |
| 2201 | |
| 2202 | static void |
| 2203 | set_maximized(struct shell_surface *shsurf, |
| 2204 | struct weston_output *output) |
| 2205 | { |
| 2206 | struct desktop_shell *shell; |
| 2207 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2208 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2209 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2210 | |
| 2211 | shell = shell_surface_get_shell(shsurf); |
| 2212 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2213 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2214 | |
| 2215 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2216 | shsurf->output->width, |
| 2217 | shsurf->output->height - panel_height); |
| 2218 | |
| 2219 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
| 2220 | } |
| 2221 | |
| 2222 | static void |
| 2223 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2224 | { |
| 2225 | struct workspace *ws; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2226 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2227 | /* undo all maximized things here */ |
| 2228 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2229 | weston_view_set_position(shsurf->view, |
| 2230 | shsurf->saved_x, |
| 2231 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2232 | |
| 2233 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2234 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2235 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2236 | shsurf->saved_rotation_valid = false; |
| 2237 | } |
| 2238 | |
| 2239 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2240 | wl_list_remove(&shsurf->view->layer_link); |
| 2241 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2242 | } |
| 2243 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2244 | static void |
| 2245 | shell_surface_set_maximized(struct wl_client *client, |
| 2246 | struct wl_resource *resource, |
| 2247 | struct wl_resource *output_resource) |
| 2248 | { |
| 2249 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2250 | struct weston_output *output; |
| 2251 | |
| 2252 | if (output_resource) |
| 2253 | output = wl_resource_get_user_data(output_resource); |
| 2254 | else |
| 2255 | output = NULL; |
| 2256 | |
| 2257 | set_maximized(shsurf, output); |
| 2258 | } |
| 2259 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2260 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2261 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2262 | { |
| 2263 | switch (surface->type) { |
| 2264 | case SHELL_SURFACE_FULLSCREEN: |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2265 | unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2266 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2267 | case SHELL_SURFACE_MAXIMIZED: |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2268 | unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2269 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2270 | case SHELL_SURFACE_NONE: |
| 2271 | case SHELL_SURFACE_TOPLEVEL: |
| 2272 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2273 | case SHELL_SURFACE_POPUP: |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2274 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2275 | default: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2276 | break; |
| 2277 | } |
| 2278 | |
| 2279 | surface->type = SHELL_SURFACE_NONE; |
| 2280 | return 0; |
| 2281 | } |
| 2282 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2283 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2284 | set_surface_type(struct shell_surface *shsurf) |
| 2285 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2286 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2287 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2288 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2289 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2290 | |
| 2291 | shsurf->type = shsurf->next_type; |
| 2292 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 2293 | |
| 2294 | switch (shsurf->type) { |
| 2295 | case SHELL_SURFACE_TOPLEVEL: |
| 2296 | break; |
| 2297 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2298 | if (pev) |
| 2299 | weston_view_set_position(shsurf->view, |
| 2300 | pev->geometry.x + shsurf->transient.x, |
| 2301 | pev->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2302 | break; |
| 2303 | |
| 2304 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2305 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2306 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2307 | shsurf->saved_y = shsurf->view->geometry.y; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2308 | shsurf->saved_position_valid = true; |
| 2309 | |
| 2310 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2311 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2312 | wl_list_init(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2313 | weston_view_geometry_dirty(shsurf->view); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2314 | shsurf->saved_rotation_valid = true; |
| 2315 | } |
| 2316 | break; |
| 2317 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2318 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2319 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2320 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2321 | break; |
| 2322 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2323 | case SHELL_SURFACE_POPUP: |
| 2324 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2325 | default: |
| 2326 | break; |
| 2327 | } |
| 2328 | } |
| 2329 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2330 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2331 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2332 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2333 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2334 | } |
| 2335 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2336 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2337 | 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] | 2338 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2339 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2340 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2341 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2342 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2343 | { |
| 2344 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2345 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2346 | |
| 2347 | surface = weston_surface_create(ec); |
| 2348 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2349 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2350 | return NULL; |
| 2351 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2352 | view = weston_view_create(surface); |
| 2353 | if (surface == NULL) { |
| 2354 | weston_log("no memory\n"); |
| 2355 | weston_surface_destroy(surface); |
| 2356 | return NULL; |
| 2357 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2358 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2359 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2360 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2361 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2362 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2363 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2364 | pixman_region32_fini(&surface->input); |
| 2365 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2366 | surface->width = w; |
| 2367 | surface->height = h; |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2368 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2369 | weston_view_configure(view, x, y, w, h); |
| 2370 | |
| 2371 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | /* Create black surface and append it to the associated fullscreen surface. |
| 2375 | * Handle size dismatch and positioning according to the method. */ |
| 2376 | static void |
| 2377 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2378 | { |
| 2379 | struct weston_output *output = shsurf->fullscreen_output; |
| 2380 | struct weston_surface *surface = shsurf->surface; |
| 2381 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2382 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2383 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2384 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2385 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2386 | restore_output_mode(output); |
| 2387 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2388 | if (!shsurf->fullscreen.black_view) |
| 2389 | shsurf->fullscreen.black_view = |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2390 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2391 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2392 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2393 | output->width, |
| 2394 | output->height); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2395 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2396 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2397 | wl_list_insert(&shsurf->view->layer_link, |
| 2398 | &shsurf->fullscreen.black_view->layer_link); |
| 2399 | shsurf->fullscreen.black_view->surface->output = output; |
| 2400 | shsurf->fullscreen.black_view->output = output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2401 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2402 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2403 | &surf_width, &surf_height); |
| 2404 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2405 | switch (shsurf->fullscreen.type) { |
| 2406 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2407 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2408 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2409 | break; |
| 2410 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2411 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2412 | if (output->width == surf_width && |
| 2413 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2414 | weston_view_set_position(shsurf->view, |
| 2415 | output->x - surf_x, |
| 2416 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2417 | break; |
| 2418 | } |
| 2419 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2420 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2421 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2422 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2423 | output_aspect = (float) output->width / |
| 2424 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2425 | /* XXX: Use surf_width and surf_height here? */ |
| 2426 | surface_aspect = (float) surface->width / |
| 2427 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2428 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2429 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2430 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2431 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2432 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2433 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2434 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2435 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2436 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2437 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2438 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2439 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2440 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2441 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2442 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2443 | break; |
| 2444 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2445 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2446 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2447 | surf_width * surface->buffer_viewport.scale, |
| 2448 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2449 | shsurf->fullscreen.framerate}; |
| 2450 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2451 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2452 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2453 | weston_view_set_position(shsurf->view, |
| 2454 | output->x - surf_x, |
| 2455 | output->y - surf_y); |
| 2456 | weston_view_configure(shsurf->fullscreen.black_view, |
| 2457 | output->x - surf_x, |
| 2458 | output->y - surf_y, |
| 2459 | output->width, |
| 2460 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2461 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2462 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2463 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2464 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2465 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2466 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2467 | break; |
| 2468 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2469 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2470 | break; |
| 2471 | default: |
| 2472 | break; |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | /* make the fullscreen and black surface at the top */ |
| 2477 | static void |
| 2478 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 2479 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2480 | struct weston_output *output = shsurf->fullscreen_output; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2481 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2482 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2483 | wl_list_remove(&shsurf->view->layer_link); |
| 2484 | wl_list_insert(&shell->fullscreen_layer.view_list, |
| 2485 | &shsurf->view->layer_link); |
| 2486 | weston_surface_damage(shsurf->surface); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2487 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2488 | if (!shsurf->fullscreen.black_view) |
| 2489 | shsurf->fullscreen.black_view = |
| 2490 | create_black_surface(shsurf->surface->compositor, |
| 2491 | shsurf->surface, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2492 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2493 | output->width, |
| 2494 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2495 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2496 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2497 | wl_list_insert(&shsurf->view->layer_link, |
| 2498 | &shsurf->fullscreen.black_view->layer_link); |
| 2499 | weston_surface_damage(shsurf->fullscreen.black_view->surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | static void |
| 2503 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2504 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2505 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2506 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2507 | } |
| 2508 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2509 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2510 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2511 | { |
| 2512 | /* XXX: using the same fields for transient type */ |
| 2513 | shsurf->transient.x = x; |
| 2514 | shsurf->transient.y = y; |
| 2515 | shsurf->transient.flags = flags; |
| 2516 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2517 | } |
| 2518 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2519 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2520 | |
| 2521 | static void |
| 2522 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2523 | { |
| 2524 | struct shell_seat *shseat = |
| 2525 | container_of(listener, |
| 2526 | struct shell_seat, seat_destroy_listener); |
| 2527 | struct shell_surface *shsurf, *prev = NULL; |
| 2528 | |
| 2529 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2530 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2531 | shseat->popup_grab.client = NULL; |
| 2532 | |
| 2533 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2534 | shsurf->popup.shseat = NULL; |
| 2535 | if (prev) { |
| 2536 | wl_list_init(&prev->popup.grab_link); |
| 2537 | } |
| 2538 | prev = shsurf; |
| 2539 | } |
| 2540 | wl_list_init(&prev->popup.grab_link); |
| 2541 | } |
| 2542 | |
| 2543 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2544 | free(shseat); |
| 2545 | } |
| 2546 | |
| 2547 | static struct shell_seat * |
| 2548 | create_shell_seat(struct weston_seat *seat) |
| 2549 | { |
| 2550 | struct shell_seat *shseat; |
| 2551 | |
| 2552 | shseat = calloc(1, sizeof *shseat); |
| 2553 | if (!shseat) { |
| 2554 | weston_log("no memory to allocate shell seat\n"); |
| 2555 | return NULL; |
| 2556 | } |
| 2557 | |
| 2558 | shseat->seat = seat; |
| 2559 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2560 | |
| 2561 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2562 | wl_signal_add(&seat->destroy_signal, |
| 2563 | &shseat->seat_destroy_listener); |
| 2564 | |
| 2565 | return shseat; |
| 2566 | } |
| 2567 | |
| 2568 | static struct shell_seat * |
| 2569 | get_shell_seat(struct weston_seat *seat) |
| 2570 | { |
| 2571 | struct wl_listener *listener; |
| 2572 | |
| 2573 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2574 | if (listener == NULL) |
| 2575 | return create_shell_seat(seat); |
| 2576 | |
| 2577 | return container_of(listener, |
| 2578 | struct shell_seat, seat_destroy_listener); |
| 2579 | } |
| 2580 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2581 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2582 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2583 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2584 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2585 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2586 | struct shell_seat *shseat = |
| 2587 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2588 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2589 | wl_fixed_t sx, sy; |
| 2590 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2591 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2592 | pointer->x, pointer->y, |
| 2593 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2594 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2595 | if (view && view->surface->resource && |
| 2596 | wl_resource_get_client(view->surface->resource) == client) { |
| 2597 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2598 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2599 | weston_pointer_set_focus(pointer, NULL, |
| 2600 | wl_fixed_from_int(0), |
| 2601 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2606 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2607 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2608 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2609 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2610 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2611 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2612 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2613 | weston_pointer_move(pointer, x, y); |
| 2614 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2615 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2616 | weston_view_from_global_fixed(pointer->focus, |
| 2617 | pointer->x, pointer->y, |
| 2618 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2619 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2620 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2624 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2625 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2626 | { |
| 2627 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2628 | struct shell_seat *shseat = |
| 2629 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2630 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2631 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2632 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2633 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2634 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2635 | resource_list = &grab->pointer->focus_resource_list; |
| 2636 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2637 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2638 | wl_resource_for_each(resource, resource_list) { |
| 2639 | wl_pointer_send_button(resource, serial, |
| 2640 | time, button, state); |
| 2641 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2642 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2643 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2644 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2645 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2646 | } |
| 2647 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2648 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2649 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2650 | } |
| 2651 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2652 | static void |
| 2653 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2654 | { |
| 2655 | popup_grab_end(grab->pointer); |
| 2656 | } |
| 2657 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2658 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2659 | popup_grab_focus, |
| 2660 | popup_grab_motion, |
| 2661 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2662 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2663 | }; |
| 2664 | |
| 2665 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2666 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2667 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2668 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2669 | struct shell_seat *shseat = |
| 2670 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2671 | struct shell_surface *shsurf; |
| 2672 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2673 | |
| 2674 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2675 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2676 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2677 | shseat->popup_grab.grab.interface = NULL; |
| 2678 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2679 | /* Send the popup_done event to all the popups open */ |
| 2680 | 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] | 2681 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2682 | shsurf->popup.shseat = NULL; |
| 2683 | if (prev) { |
| 2684 | wl_list_init(&prev->popup.grab_link); |
| 2685 | } |
| 2686 | prev = shsurf; |
| 2687 | } |
| 2688 | wl_list_init(&prev->popup.grab_link); |
| 2689 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | static void |
| 2694 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2695 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2696 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2697 | |
| 2698 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2699 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2700 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2701 | /* We must make sure here that this popup was opened after |
| 2702 | * a mouse press, and not just by moving around with other |
| 2703 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2704 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2705 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2706 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2707 | 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] | 2708 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2709 | } else { |
| 2710 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2711 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | static void |
| 2715 | remove_popup_grab(struct shell_surface *shsurf) |
| 2716 | { |
| 2717 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2718 | |
| 2719 | wl_list_remove(&shsurf->popup.grab_link); |
| 2720 | wl_list_init(&shsurf->popup.grab_link); |
| 2721 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2722 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2723 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2728 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2729 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2730 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2731 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2732 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2733 | shsurf->surface->output = parent_view->output; |
| 2734 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2735 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2736 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2737 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2738 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2739 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2740 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2741 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2742 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2743 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2744 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2745 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2746 | } |
| 2747 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2748 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2749 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2750 | shell_surface_move, |
| 2751 | shell_surface_resize, |
| 2752 | shell_surface_set_toplevel, |
| 2753 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2754 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2755 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2756 | shell_surface_set_maximized, |
| 2757 | shell_surface_set_title, |
| 2758 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2759 | }; |
| 2760 | |
| 2761 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2762 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2763 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2764 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2765 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2766 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2767 | remove_popup_grab(shsurf); |
| 2768 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2769 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2770 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2771 | shell_surface_is_top_fullscreen(shsurf)) |
| 2772 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2773 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2774 | if (shsurf->fullscreen.black_view) |
| 2775 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2776 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2777 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2778 | * we can always remove the listener. |
| 2779 | */ |
| 2780 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2781 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2782 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2783 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2784 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2785 | weston_view_destroy(shsurf->view); |
| 2786 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2787 | wl_list_remove(&shsurf->link); |
| 2788 | free(shsurf); |
| 2789 | } |
| 2790 | |
| 2791 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2792 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2793 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2794 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2795 | |
| 2796 | destroy_shell_surface(shsurf); |
| 2797 | } |
| 2798 | |
| 2799 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2800 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2801 | { |
| 2802 | struct shell_surface *shsurf = container_of(listener, |
| 2803 | struct shell_surface, |
| 2804 | surface_destroy_listener); |
| 2805 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2806 | if (shsurf->resource) |
| 2807 | wl_resource_destroy(shsurf->resource); |
| 2808 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2809 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2810 | } |
| 2811 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2812 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2813 | 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] | 2814 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2815 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2816 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2817 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2818 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2819 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2820 | else |
| 2821 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2822 | } |
| 2823 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2824 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2825 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2826 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2827 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2828 | struct shell_surface *shsurf; |
| 2829 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2830 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2831 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2832 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2833 | } |
| 2834 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2835 | shsurf = calloc(1, sizeof *shsurf); |
| 2836 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2837 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2838 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2839 | } |
| 2840 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2841 | shsurf->view = weston_view_create(surface); |
| 2842 | if (!shsurf->view) { |
| 2843 | weston_log("no memory to allocate shell surface\n"); |
| 2844 | free(shsurf); |
| 2845 | return NULL; |
| 2846 | } |
| 2847 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2848 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2849 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2850 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2851 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2852 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2853 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2854 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2855 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2856 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2857 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2858 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2859 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2860 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2861 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2862 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2863 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2864 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2865 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2866 | |
| 2867 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2868 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2869 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2870 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2871 | /* empty when not in use */ |
| 2872 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2873 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2874 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2875 | wl_list_init(&shsurf->workspace_transform.link); |
| 2876 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2877 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2878 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2879 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2880 | shsurf->client = client; |
| 2881 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2882 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2883 | } |
| 2884 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2885 | static struct weston_view * |
| 2886 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2887 | { |
| 2888 | return shsurf->view; |
| 2889 | } |
| 2890 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2891 | static void |
| 2892 | shell_get_shell_surface(struct wl_client *client, |
| 2893 | struct wl_resource *resource, |
| 2894 | uint32_t id, |
| 2895 | struct wl_resource *surface_resource) |
| 2896 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2897 | struct weston_surface *surface = |
| 2898 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2899 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2900 | struct shell_surface *shsurf; |
| 2901 | |
| 2902 | if (get_shell_surface(surface)) { |
| 2903 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2904 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2905 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2906 | return; |
| 2907 | } |
| 2908 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2909 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2910 | if (!shsurf) { |
| 2911 | wl_resource_post_error(surface_resource, |
| 2912 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2913 | "surface->configure already set"); |
| 2914 | return; |
| 2915 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2916 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2917 | shsurf->resource = |
| 2918 | wl_resource_create(client, |
| 2919 | &wl_shell_surface_interface, 1, id); |
| 2920 | wl_resource_set_implementation(shsurf->resource, |
| 2921 | &shell_surface_implementation, |
| 2922 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 2926 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2927 | }; |
| 2928 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2929 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 2930 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 2931 | |
| 2932 | static int |
| 2933 | screensaver_timeout(void *data) |
| 2934 | { |
| 2935 | struct desktop_shell *shell = data; |
| 2936 | |
| 2937 | shell_fade(shell, FADE_OUT); |
| 2938 | |
| 2939 | return 1; |
| 2940 | } |
| 2941 | |
| 2942 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2943 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2944 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2945 | struct desktop_shell *shell = |
| 2946 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2947 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2948 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2949 | |
| 2950 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 2951 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2955 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2956 | { |
| 2957 | if (shell->screensaver.binding) |
| 2958 | return; |
| 2959 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2960 | if (!shell->screensaver.path) { |
| 2961 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2962 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2963 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2964 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2965 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2966 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2967 | return; |
| 2968 | } |
| 2969 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2970 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2971 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2972 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2973 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2977 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2978 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2979 | if (shell->screensaver.process.pid == 0) |
| 2980 | return; |
| 2981 | |
| 2982 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2986 | 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] | 2987 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2988 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2989 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2990 | if (width == 0) |
| 2991 | return; |
| 2992 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2993 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 2994 | if (v->output == ev->output && v != ev) { |
| 2995 | weston_view_unmap(v); |
| 2996 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2997 | } |
| 2998 | } |
| 2999 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3000 | 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] | 3001 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3002 | if (wl_list_empty(&ev->layer_link)) { |
| 3003 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3004 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3005 | } |
| 3006 | } |
| 3007 | |
| 3008 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3009 | 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] | 3010 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3011 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3012 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3013 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3014 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3015 | |
| 3016 | configure_static_view(view, &shell->background_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3020 | desktop_shell_set_background(struct wl_client *client, |
| 3021 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3022 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3023 | struct wl_resource *surface_resource) |
| 3024 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3025 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3026 | struct weston_surface *surface = |
| 3027 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3028 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3029 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3030 | if (surface->configure) { |
| 3031 | wl_resource_post_error(surface_resource, |
| 3032 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3033 | "surface role already assigned"); |
| 3034 | return; |
| 3035 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3036 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3037 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3038 | weston_view_destroy(view); |
| 3039 | view = weston_view_create(surface); |
| 3040 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3041 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3042 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3043 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3044 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3045 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3046 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3047 | surface->output->width, |
| 3048 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3052 | 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] | 3053 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3054 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3055 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3056 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3057 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3058 | |
| 3059 | configure_static_view(view, &shell->panel_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3063 | desktop_shell_set_panel(struct wl_client *client, |
| 3064 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3065 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3066 | struct wl_resource *surface_resource) |
| 3067 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3068 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3069 | struct weston_surface *surface = |
| 3070 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3071 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3072 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3073 | if (surface->configure) { |
| 3074 | wl_resource_post_error(surface_resource, |
| 3075 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3076 | "surface role already assigned"); |
| 3077 | return; |
| 3078 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3079 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3080 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3081 | weston_view_destroy(view); |
| 3082 | view = weston_view_create(surface); |
| 3083 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3084 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3085 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3086 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3087 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3088 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3089 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3090 | surface->output->width, |
| 3091 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3092 | } |
| 3093 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3094 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3095 | 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] | 3096 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3097 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3098 | struct weston_view *view; |
| 3099 | |
| 3100 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3101 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3102 | if (width == 0) |
| 3103 | return; |
| 3104 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3105 | surface->width = width; |
| 3106 | surface->height = height; |
| 3107 | view->geometry.width = width; |
| 3108 | view->geometry.height = height; |
| 3109 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3110 | |
| 3111 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3112 | wl_list_insert(&shell->lock_layer.view_list, |
| 3113 | &view->layer_link); |
| 3114 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3115 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3116 | } |
| 3117 | } |
| 3118 | |
| 3119 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3120 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3121 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3122 | struct desktop_shell *shell = |
| 3123 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3124 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3125 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3126 | shell->lock_surface = NULL; |
| 3127 | } |
| 3128 | |
| 3129 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3130 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3131 | struct wl_resource *resource, |
| 3132 | struct wl_resource *surface_resource) |
| 3133 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3134 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3135 | struct weston_surface *surface = |
| 3136 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3137 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3138 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3139 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3140 | if (!shell->locked) |
| 3141 | return; |
| 3142 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3143 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3144 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3145 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3146 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3147 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3148 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3149 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3150 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3151 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3155 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3156 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3157 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3158 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3159 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3160 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3161 | wl_list_remove(&shell->lock_layer.link); |
| 3162 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3163 | &shell->fullscreen_layer.link); |
| 3164 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3165 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3166 | if (shell->showing_input_panels) { |
| 3167 | wl_list_insert(&shell->panel_layer.link, |
| 3168 | &shell->input_panel_layer.link); |
| 3169 | wl_list_insert(&shell->input_panel_layer.link, |
| 3170 | &ws->layer.link); |
| 3171 | } else { |
| 3172 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3173 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3174 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3175 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3176 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3177 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3178 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3179 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | static void |
| 3183 | desktop_shell_unlock(struct wl_client *client, |
| 3184 | struct wl_resource *resource) |
| 3185 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3186 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3187 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3188 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3189 | |
| 3190 | if (shell->locked) |
| 3191 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3192 | } |
| 3193 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3194 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3195 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3196 | struct wl_resource *resource, |
| 3197 | struct wl_resource *surface_resource) |
| 3198 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3199 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3200 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3201 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3202 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3203 | } |
| 3204 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3205 | static void |
| 3206 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3207 | struct wl_resource *resource) |
| 3208 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3209 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3210 | |
| 3211 | shell_fade_startup(shell); |
| 3212 | } |
| 3213 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3214 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3215 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3216 | desktop_shell_set_panel, |
| 3217 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3218 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3219 | desktop_shell_set_grab_surface, |
| 3220 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3221 | }; |
| 3222 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3223 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3224 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3225 | { |
| 3226 | struct shell_surface *shsurf; |
| 3227 | |
| 3228 | shsurf = get_shell_surface(surface); |
| 3229 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3230 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3231 | return shsurf->type; |
| 3232 | } |
| 3233 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3234 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3235 | 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] | 3236 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3237 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3238 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3239 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3240 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3241 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3242 | if (surface == NULL) |
| 3243 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3244 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3245 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3246 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3247 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3248 | return; |
| 3249 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3250 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3254 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3255 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3256 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3257 | struct weston_surface *surface; |
| 3258 | struct shell_surface *shsurf; |
| 3259 | |
| 3260 | surface = weston_surface_get_main_surface(focus); |
| 3261 | if (surface == NULL) |
| 3262 | return; |
| 3263 | |
| 3264 | shsurf = get_shell_surface(surface); |
| 3265 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3266 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
| 3267 | return; |
| 3268 | |
| 3269 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3270 | } |
| 3271 | |
| 3272 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3273 | 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] | 3274 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3275 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3276 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3277 | uint32_t edges = 0; |
| 3278 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3279 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3280 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3281 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3282 | if (surface == NULL) |
| 3283 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3284 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3285 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3286 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3287 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3288 | return; |
| 3289 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3290 | weston_view_from_global(shsurf->view, |
| 3291 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3292 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3293 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3294 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3295 | if (x < shsurf->view->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3296 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3297 | else if (x < 2 * shsurf->view->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3298 | edges |= 0; |
| 3299 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3300 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3301 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3302 | if (y < shsurf->view->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3303 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3304 | else if (y < 2 * shsurf->view->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3305 | edges |= 0; |
| 3306 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3307 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3308 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3309 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3313 | 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] | 3314 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3315 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3316 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3317 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3318 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3319 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3320 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3321 | /* XXX: broken for windows containing sub-surfaces */ |
| 3322 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3323 | if (surface == NULL) |
| 3324 | return; |
| 3325 | |
| 3326 | shsurf = get_shell_surface(surface); |
| 3327 | if (!shsurf) |
| 3328 | return; |
| 3329 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3330 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3331 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3332 | if (shsurf->view->alpha > 1.0) |
| 3333 | shsurf->view->alpha = 1.0; |
| 3334 | if (shsurf->view->alpha < step) |
| 3335 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3336 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3337 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3338 | weston_surface_damage(surface); |
| 3339 | } |
| 3340 | |
| 3341 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3342 | 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] | 3343 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3344 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3345 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3346 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3347 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3348 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3349 | |
| 3350 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3351 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3352 | wl_fixed_to_double(seat->pointer->x), |
| 3353 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3354 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3355 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3356 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3357 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3358 | increment = -output->zoom.increment; |
| 3359 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3360 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3361 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3362 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3363 | else |
| 3364 | increment = 0; |
| 3365 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3366 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3367 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3368 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3369 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3370 | else if (output->zoom.level > output->zoom.max_level) |
| 3371 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3372 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3373 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3374 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3375 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3376 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3377 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3378 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3379 | } |
| 3380 | } |
| 3381 | } |
| 3382 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3383 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3384 | 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] | 3385 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3386 | { |
| 3387 | do_zoom(seat, time, 0, axis, value); |
| 3388 | } |
| 3389 | |
| 3390 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3391 | 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] | 3392 | void *data) |
| 3393 | { |
| 3394 | do_zoom(seat, time, key, 0, 0); |
| 3395 | } |
| 3396 | |
| 3397 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3398 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3399 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3400 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3401 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3402 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3403 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3407 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 3408 | |
| 3409 | struct alt_tab { |
| 3410 | struct desktop_shell *shell; |
| 3411 | struct weston_keyboard_grab grab; |
| 3412 | |
| 3413 | struct wl_list *current; |
| 3414 | |
| 3415 | struct wl_list preview_list; |
| 3416 | }; |
| 3417 | |
| 3418 | struct alt_tab_preview { |
| 3419 | struct alt_tab *alt_tab; |
| 3420 | |
| 3421 | struct weston_view *view; |
| 3422 | struct weston_transform transform; |
| 3423 | |
| 3424 | struct wl_listener listener; |
| 3425 | |
| 3426 | struct wl_list link; |
| 3427 | }; |
| 3428 | |
| 3429 | static void |
| 3430 | alt_tab_next(struct alt_tab *alt_tab) |
| 3431 | { |
| 3432 | alt_tab->current = alt_tab->current->next; |
| 3433 | |
| 3434 | /* Make sure we're not pointing to the list header e.g. after |
| 3435 | * cycling through the whole list. */ |
| 3436 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3437 | alt_tab->current = alt_tab->current->next; |
| 3438 | } |
| 3439 | |
| 3440 | static void |
| 3441 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 3442 | { |
| 3443 | struct alt_tab_preview *preview, *next; |
| 3444 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 3445 | |
| 3446 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 3447 | preview = wl_container_of(alt_tab->current, preview, link); |
| 3448 | |
| 3449 | activate(alt_tab->shell, preview->view->surface, |
| 3450 | (struct weston_seat *) keyboard->seat); |
| 3451 | } |
| 3452 | |
| 3453 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 3454 | wl_list_remove(&preview->link); |
| 3455 | wl_list_remove(&preview->listener.link); |
| 3456 | weston_view_destroy(preview->view); |
| 3457 | free(preview); |
| 3458 | } |
| 3459 | |
| 3460 | weston_keyboard_end_grab(keyboard); |
| 3461 | if (keyboard->input_method_resource) |
| 3462 | keyboard->grab = &keyboard->input_method_grab; |
| 3463 | |
| 3464 | free(alt_tab); |
| 3465 | } |
| 3466 | |
| 3467 | static void |
| 3468 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3469 | { |
| 3470 | struct alt_tab_preview *preview = |
| 3471 | container_of(listener, struct alt_tab_preview, listener); |
| 3472 | struct alt_tab *alt_tab = preview->alt_tab; |
| 3473 | int advance = 0; |
| 3474 | |
| 3475 | /* If the preview that we're removing is the currently selected one, |
| 3476 | * we want to move to the next one. So we move to ->prev and then |
| 3477 | * call _next() after removing the preview. */ |
| 3478 | if (alt_tab->current == &preview->link) { |
| 3479 | alt_tab->current = alt_tab->current->prev; |
| 3480 | advance = 1; |
| 3481 | } |
| 3482 | |
| 3483 | wl_list_remove(&preview->listener.link); |
| 3484 | wl_list_remove(&preview->link); |
| 3485 | |
| 3486 | free(preview); |
| 3487 | |
| 3488 | if (advance) |
| 3489 | alt_tab_next(alt_tab); |
| 3490 | |
| 3491 | /* If the last preview goes away, stop the alt-tab */ |
| 3492 | if (wl_list_empty(alt_tab->current)) |
| 3493 | alt_tab_destroy(alt_tab); |
| 3494 | } |
| 3495 | |
| 3496 | static void |
| 3497 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 3498 | uint32_t time, uint32_t key, uint32_t state_w) |
| 3499 | { |
| 3500 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3501 | enum wl_keyboard_key_state state = state_w; |
| 3502 | |
| 3503 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 3504 | alt_tab_next(alt_tab); |
| 3505 | } |
| 3506 | |
| 3507 | static void |
| 3508 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 3509 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3510 | uint32_t mods_locked, uint32_t group) |
| 3511 | { |
| 3512 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3513 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 3514 | |
| 3515 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 3516 | alt_tab_destroy(alt_tab); |
| 3517 | } |
| 3518 | |
| 3519 | static void |
| 3520 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 3521 | { |
| 3522 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3523 | |
| 3524 | alt_tab_destroy(alt_tab); |
| 3525 | } |
| 3526 | |
| 3527 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 3528 | alt_tab_key, |
| 3529 | alt_tab_modifier, |
| 3530 | alt_tab_cancel, |
| 3531 | }; |
| 3532 | |
| 3533 | static int |
| 3534 | view_for_alt_tab(struct weston_view *view) |
| 3535 | { |
| 3536 | if (!get_shell_surface(view->surface)) |
| 3537 | return 0; |
| 3538 | |
| 3539 | if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT) |
| 3540 | return 0; |
| 3541 | |
| 3542 | if (view != get_default_view(view->surface)) |
| 3543 | return 0; |
| 3544 | |
| 3545 | return 1; |
| 3546 | } |
| 3547 | |
| 3548 | static void |
| 3549 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 3550 | void *data) |
| 3551 | { |
| 3552 | struct alt_tab *alt_tab; |
| 3553 | struct desktop_shell *shell = data; |
| 3554 | struct weston_output *output = get_default_output(shell->compositor); |
| 3555 | struct workspace *ws; |
| 3556 | struct weston_view *view; |
| 3557 | int num_surfaces = 0; |
| 3558 | int x, y, side, margin; |
| 3559 | |
| 3560 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3561 | |
| 3562 | if (view_for_alt_tab(view)) |
| 3563 | num_surfaces++; |
| 3564 | } |
| 3565 | |
| 3566 | if (!num_surfaces) |
| 3567 | return; |
| 3568 | |
| 3569 | alt_tab = malloc(sizeof *alt_tab); |
| 3570 | if (!alt_tab) |
| 3571 | return; |
| 3572 | |
| 3573 | alt_tab->shell = shell; |
| 3574 | wl_list_init(&alt_tab->preview_list); |
| 3575 | alt_tab->current = &alt_tab->preview_list; |
| 3576 | |
| 3577 | restore_all_output_modes(shell->compositor); |
| 3578 | lower_fullscreen_layer(alt_tab->shell); |
| 3579 | |
| 3580 | alt_tab->grab.interface = &alt_tab_grab; |
| 3581 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 3582 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 3583 | |
| 3584 | ws = get_current_workspace(shell); |
| 3585 | |
| 3586 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 3587 | * and/or add a black surrounding background à la gnome-shell */ |
| 3588 | |
| 3589 | /* Determine the size for each preview */ |
| 3590 | side = output->width / num_surfaces; |
| 3591 | if (side > 200) |
| 3592 | side = 200; |
| 3593 | margin = side / 4; |
| 3594 | side -= margin; |
| 3595 | |
| 3596 | x = margin; |
| 3597 | y = (output->height - side) / 2; |
| 3598 | |
| 3599 | /* Create a view for each surface */ |
| 3600 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3601 | struct alt_tab_preview *preview; |
| 3602 | struct weston_view *v; |
| 3603 | float scale; |
| 3604 | |
| 3605 | if (!view_for_alt_tab(view)) |
| 3606 | continue; |
| 3607 | |
| 3608 | preview = malloc(sizeof *preview); |
| 3609 | if (!preview) { |
| 3610 | alt_tab_destroy(alt_tab); |
| 3611 | return; |
| 3612 | } |
| 3613 | |
| 3614 | preview->alt_tab = alt_tab; |
| 3615 | |
| 3616 | preview->view = v = weston_view_create(view->surface); |
| 3617 | v->output = view->output; |
| 3618 | weston_view_restack(v, &ws->layer.view_list); |
| 3619 | weston_view_configure(v, x, y, view->geometry.width, view->geometry.height); |
| 3620 | |
| 3621 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 3622 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 3623 | |
| 3624 | if (view->geometry.width > view->geometry.height) |
| 3625 | scale = side / (float) view->geometry.width; |
| 3626 | else |
| 3627 | scale = side / (float) view->geometry.height; |
| 3628 | |
| 3629 | wl_list_insert(&v->geometry.transformation_list, |
| 3630 | &preview->transform.link); |
| 3631 | weston_matrix_init(&preview->transform.matrix); |
| 3632 | weston_matrix_scale(&preview->transform.matrix, |
| 3633 | scale, scale, 1.0f); |
| 3634 | |
| 3635 | weston_view_geometry_dirty(v); |
| 3636 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 3637 | |
| 3638 | /* Insert at the end of the list */ |
| 3639 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 3640 | |
| 3641 | x += side + margin; |
| 3642 | } |
| 3643 | |
| 3644 | /* Start at the second preview so a simple <alt>tab changes window. |
| 3645 | * We set `current' to the first preview and not the second because |
| 3646 | * we're going to receive a key press callback for the initial |
| 3647 | * <alt>tab which will make `current' point to the second element. */ |
| 3648 | alt_tab_next(alt_tab); |
| 3649 | } |
| 3650 | |
| 3651 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3652 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3653 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3654 | { |
| 3655 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3656 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3657 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3658 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3659 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3660 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3661 | weston_pointer_move(pointer, x, y); |
| 3662 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3663 | if (!shsurf) |
| 3664 | return; |
| 3665 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3666 | cx = 0.5f * shsurf->view->geometry.width; |
| 3667 | cy = 0.5f * shsurf->view->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3668 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3669 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3670 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3671 | r = sqrtf(dx * dx + dy * dy); |
| 3672 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3673 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3674 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3675 | |
| 3676 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3677 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3678 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3679 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3680 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3681 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3682 | |
| 3683 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3684 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3685 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3686 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3687 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3688 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3689 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3690 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3691 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3692 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3693 | wl_list_init(&shsurf->rotation.transform.link); |
| 3694 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3695 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3696 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3697 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3698 | /* We need to adjust the position of the surface |
| 3699 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3700 | cposx = shsurf->view->geometry.x + cx; |
| 3701 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3702 | dposx = rotate->center.x - cposx; |
| 3703 | dposy = rotate->center.y - cposy; |
| 3704 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3705 | weston_view_set_position(shsurf->view, |
| 3706 | shsurf->view->geometry.x + dposx, |
| 3707 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3708 | } |
| 3709 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3710 | /* Repaint implies weston_surface_update_transform(), which |
| 3711 | * lazily applies the damage due to rotation update. |
| 3712 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3713 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3717 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3718 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3719 | { |
| 3720 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3721 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3722 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3723 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3724 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3725 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3726 | if (pointer->button_count == 0 && |
| 3727 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3728 | if (shsurf) |
| 3729 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3730 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3731 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3732 | free(rotate); |
| 3733 | } |
| 3734 | } |
| 3735 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3736 | static void |
| 3737 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3738 | { |
| 3739 | struct rotate_grab *rotate = |
| 3740 | container_of(grab, struct rotate_grab, base.grab); |
| 3741 | |
| 3742 | shell_grab_end(&rotate->base); |
| 3743 | free(rotate); |
| 3744 | } |
| 3745 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3746 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3747 | noop_grab_focus, |
| 3748 | rotate_grab_motion, |
| 3749 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3750 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3751 | }; |
| 3752 | |
| 3753 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3754 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3755 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3756 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3757 | float dx, dy; |
| 3758 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3759 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3760 | rotate = malloc(sizeof *rotate); |
| 3761 | if (!rotate) |
| 3762 | return; |
| 3763 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3764 | weston_view_to_global_float(surface->view, |
| 3765 | surface->view->geometry.width * 0.5f, |
| 3766 | surface->view->geometry.height * 0.5f, |
| 3767 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3768 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3769 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3770 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3771 | r = sqrtf(dx * dx + dy * dy); |
| 3772 | if (r > 20.0f) { |
| 3773 | struct weston_matrix inverse; |
| 3774 | |
| 3775 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3776 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3777 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3778 | |
| 3779 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3780 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3781 | } else { |
| 3782 | weston_matrix_init(&surface->rotation.rotation); |
| 3783 | weston_matrix_init(&rotate->rotation); |
| 3784 | } |
| 3785 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3786 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3787 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3791 | 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] | 3792 | void *data) |
| 3793 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3794 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3795 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3796 | struct shell_surface *surface; |
| 3797 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3798 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3799 | if (base_surface == NULL) |
| 3800 | return; |
| 3801 | |
| 3802 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3803 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 3804 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3805 | return; |
| 3806 | |
| 3807 | surface_rotate(surface, seat); |
| 3808 | } |
| 3809 | |
| 3810 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3811 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 3812 | { |
| 3813 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3814 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3815 | |
| 3816 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3817 | wl_list_for_each_reverse_safe(view, prev, |
| 3818 | &shell->fullscreen_layer.view_list, |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3819 | layer_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3820 | weston_view_restack(view, &ws->layer.view_list); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3824 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3825 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3826 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3827 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3828 | struct weston_view *main_view; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3829 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3830 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3831 | struct weston_surface *old_es; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3832 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3833 | main_surface = weston_surface_get_main_surface(es); |
| 3834 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3835 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3836 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3837 | state = ensure_focus_state(shell, seat); |
| 3838 | if (state == NULL) |
| 3839 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3840 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3841 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3842 | state->keyboard_focus = es; |
| 3843 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3844 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3845 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3846 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3847 | case SHELL_SURFACE_FULLSCREEN: |
| 3848 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3849 | shell_stack_fullscreen(get_shell_surface(main_surface)); |
| 3850 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3851 | return; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 3852 | case SHELL_SURFACE_TOPLEVEL: |
| 3853 | case SHELL_SURFACE_TRANSIENT: |
| 3854 | case SHELL_SURFACE_MAXIMIZED: |
| 3855 | case SHELL_SURFACE_POPUP: |
| 3856 | case SHELL_SURFACE_XWAYLAND: |
| 3857 | case SHELL_SURFACE_NONE: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3858 | default: |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3859 | restore_all_output_modes(shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3860 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3861 | main_view = get_default_view(main_surface); |
| 3862 | if (main_view) |
| 3863 | weston_view_restack(main_view, &ws->layer.view_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3864 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3865 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3866 | |
| 3867 | if (shell->focus_animation_type != ANIMATION_NONE) |
| 3868 | 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] | 3869 | } |
| 3870 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3871 | /* no-op func for checking black surface */ |
| 3872 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3873 | 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] | 3874 | { |
| 3875 | } |
| 3876 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3877 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3878 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 3879 | { |
| 3880 | if (es->configure == black_surface_configure) { |
| 3881 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3882 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3883 | return true; |
| 3884 | } |
| 3885 | return false; |
| 3886 | } |
| 3887 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3888 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3889 | activate_binding(struct weston_seat *seat, |
| 3890 | struct desktop_shell *shell, |
| 3891 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3892 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3893 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3894 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3895 | if (!focus) |
| 3896 | return; |
| 3897 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3898 | if (is_black_surface(focus, &main_surface)) |
| 3899 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3900 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3901 | main_surface = weston_surface_get_main_surface(focus); |
| 3902 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3903 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3904 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3905 | activate(shell, focus, seat); |
| 3906 | } |
| 3907 | |
| 3908 | static void |
| 3909 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 3910 | void *data) |
| 3911 | { |
| 3912 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 3913 | return; |
| 3914 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3915 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | static void |
| 3919 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3920 | { |
| 3921 | if (seat->touch->grab != &seat->touch->default_grab) |
| 3922 | return; |
| 3923 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3924 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3928 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3929 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3930 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3931 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3932 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3933 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3934 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3935 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3936 | |
| 3937 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3938 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3939 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3940 | * toplevel layers. This way nothing else can show or receive |
| 3941 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3942 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3943 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3944 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3945 | if (shell->showing_input_panels) |
| 3946 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3947 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3948 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3949 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3950 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3951 | launch_screensaver(shell); |
| 3952 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3953 | /* TODO: disable bindings that should not work while locked. */ |
| 3954 | |
| 3955 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3959 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3960 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3961 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3962 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3963 | return; |
| 3964 | } |
| 3965 | |
| 3966 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3967 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3968 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3969 | return; |
| 3970 | } |
| 3971 | |
| 3972 | if (shell->prepare_event_sent) |
| 3973 | return; |
| 3974 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3975 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3976 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3977 | } |
| 3978 | |
| 3979 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3980 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3981 | { |
| 3982 | struct desktop_shell *shell = data; |
| 3983 | |
| 3984 | shell->fade.animation = NULL; |
| 3985 | |
| 3986 | switch (shell->fade.type) { |
| 3987 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3988 | weston_surface_destroy(shell->fade.view->surface); |
| 3989 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3990 | break; |
| 3991 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3992 | lock(shell); |
| 3993 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 3994 | default: |
| 3995 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3996 | } |
| 3997 | } |
| 3998 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3999 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4000 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4001 | { |
| 4002 | struct weston_compositor *compositor = shell->compositor; |
| 4003 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4004 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4005 | |
| 4006 | surface = weston_surface_create(compositor); |
| 4007 | if (!surface) |
| 4008 | return NULL; |
| 4009 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4010 | view = weston_view_create(surface); |
| 4011 | if (!view) { |
| 4012 | weston_surface_destroy(surface); |
| 4013 | return NULL; |
| 4014 | } |
| 4015 | |
| 4016 | weston_view_configure(view, 0, 0, 8192, 8192); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4017 | 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] | 4018 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4019 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4020 | pixman_region32_init(&surface->input); |
| 4021 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4022 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4023 | } |
| 4024 | |
| 4025 | static void |
| 4026 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4027 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4028 | float tint; |
| 4029 | |
| 4030 | switch (type) { |
| 4031 | case FADE_IN: |
| 4032 | tint = 0.0; |
| 4033 | break; |
| 4034 | case FADE_OUT: |
| 4035 | tint = 1.0; |
| 4036 | break; |
| 4037 | default: |
| 4038 | weston_log("shell: invalid fade type\n"); |
| 4039 | return; |
| 4040 | } |
| 4041 | |
| 4042 | shell->fade.type = type; |
| 4043 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4044 | if (shell->fade.view == NULL) { |
| 4045 | shell->fade.view = shell_fade_create_surface(shell); |
| 4046 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4047 | return; |
| 4048 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4049 | shell->fade.view->alpha = 1.0 - tint; |
| 4050 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4054 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4055 | else |
| 4056 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4057 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4058 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4059 | shell_fade_done, shell); |
| 4060 | } |
| 4061 | |
| 4062 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4063 | do_shell_fade_startup(void *data) |
| 4064 | { |
| 4065 | struct desktop_shell *shell = data; |
| 4066 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4067 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4068 | shell_fade(shell, FADE_IN); |
| 4069 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4070 | weston_surface_destroy(shell->fade.view->surface); |
| 4071 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4072 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | static void |
| 4076 | shell_fade_startup(struct desktop_shell *shell) |
| 4077 | { |
| 4078 | struct wl_event_loop *loop; |
| 4079 | |
| 4080 | if (!shell->fade.startup_timer) |
| 4081 | return; |
| 4082 | |
| 4083 | wl_event_source_remove(shell->fade.startup_timer); |
| 4084 | shell->fade.startup_timer = NULL; |
| 4085 | |
| 4086 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4087 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4088 | } |
| 4089 | |
| 4090 | static int |
| 4091 | fade_startup_timeout(void *data) |
| 4092 | { |
| 4093 | struct desktop_shell *shell = data; |
| 4094 | |
| 4095 | shell_fade_startup(shell); |
| 4096 | return 0; |
| 4097 | } |
| 4098 | |
| 4099 | static void |
| 4100 | shell_fade_init(struct desktop_shell *shell) |
| 4101 | { |
| 4102 | /* Make compositor output all black, and wait for the desktop-shell |
| 4103 | * client to signal it is ready, then fade in. The timer triggers a |
| 4104 | * fade-in, in case the desktop-shell client takes too long. |
| 4105 | */ |
| 4106 | |
| 4107 | struct wl_event_loop *loop; |
| 4108 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4109 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4110 | weston_log("%s: warning: fade surface already exists\n", |
| 4111 | __func__); |
| 4112 | return; |
| 4113 | } |
| 4114 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4115 | shell->fade.view = shell_fade_create_surface(shell); |
| 4116 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4117 | return; |
| 4118 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4119 | weston_view_update_transform(shell->fade.view); |
| 4120 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4121 | |
| 4122 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4123 | shell->fade.startup_timer = |
| 4124 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4125 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4126 | } |
| 4127 | |
| 4128 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4129 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4130 | { |
| 4131 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4132 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4133 | |
| 4134 | shell_fade(shell, FADE_OUT); |
| 4135 | /* lock() is called from shell_fade_done() */ |
| 4136 | } |
| 4137 | |
| 4138 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4139 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4140 | { |
| 4141 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4142 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4143 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4144 | unlock(shell); |
| 4145 | } |
| 4146 | |
| 4147 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4148 | show_input_panels(struct wl_listener *listener, void *data) |
| 4149 | { |
| 4150 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4151 | container_of(listener, struct desktop_shell, |
| 4152 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4153 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4154 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4155 | shell->text_input.surface = (struct weston_surface*)data; |
| 4156 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4157 | if (shell->showing_input_panels) |
| 4158 | return; |
| 4159 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4160 | shell->showing_input_panels = true; |
| 4161 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4162 | if (!shell->locked) |
| 4163 | wl_list_insert(&shell->panel_layer.link, |
| 4164 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4165 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4166 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4167 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4168 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4169 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4170 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4171 | &ipsurf->view->layer_link); |
| 4172 | weston_view_geometry_dirty(ipsurf->view); |
| 4173 | weston_view_update_transform(ipsurf->view); |
| 4174 | weston_surface_damage(ipsurf->surface); |
| 4175 | weston_slide_run(ipsurf->view, ipsurf->view->geometry.height, |
| 4176 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | static void |
| 4181 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4182 | { |
| 4183 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4184 | container_of(listener, struct desktop_shell, |
| 4185 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4186 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4187 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4188 | if (!shell->showing_input_panels) |
| 4189 | return; |
| 4190 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4191 | shell->showing_input_panels = false; |
| 4192 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4193 | if (!shell->locked) |
| 4194 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4195 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4196 | wl_list_for_each_safe(view, next, |
| 4197 | &shell->input_panel_layer.view_list, layer_link) |
| 4198 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4202 | update_input_panels(struct wl_listener *listener, void *data) |
| 4203 | { |
| 4204 | struct desktop_shell *shell = |
| 4205 | container_of(listener, struct desktop_shell, |
| 4206 | update_input_panel_listener); |
| 4207 | |
| 4208 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4209 | } |
| 4210 | |
| 4211 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4212 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4213 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4214 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4215 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4216 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4217 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4218 | |
| 4219 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4220 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4221 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4222 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4226 | weston_view_set_initial_position(struct weston_view *view, |
| 4227 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4228 | { |
| 4229 | struct weston_compositor *compositor = shell->compositor; |
| 4230 | int ix = 0, iy = 0; |
| 4231 | int range_x, range_y; |
| 4232 | int dx, dy, x, y, panel_height; |
| 4233 | struct weston_output *output, *target_output = NULL; |
| 4234 | struct weston_seat *seat; |
| 4235 | |
| 4236 | /* As a heuristic place the new window on the same output as the |
| 4237 | * pointer. Falling back to the output containing 0, 0. |
| 4238 | * |
| 4239 | * TODO: Do something clever for touch too? |
| 4240 | */ |
| 4241 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4242 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4243 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4244 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4245 | break; |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4250 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4251 | target_output = output; |
| 4252 | break; |
| 4253 | } |
| 4254 | } |
| 4255 | |
| 4256 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4257 | weston_view_set_position(view, 10 + random() % 400, |
| 4258 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4259 | return; |
| 4260 | } |
| 4261 | |
| 4262 | /* Valid range within output where the surface will still be onscreen. |
| 4263 | * If this is negative it means that the surface is bigger than |
| 4264 | * output. |
| 4265 | */ |
| 4266 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4267 | range_x = target_output->width - view->geometry.width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4268 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4269 | view->geometry.height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4270 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4271 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4272 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4273 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4274 | dx = 0; |
| 4275 | |
| 4276 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4277 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4278 | else |
| 4279 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4280 | |
| 4281 | x = target_output->x + dx; |
| 4282 | y = target_output->y + dy; |
| 4283 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4284 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4288 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4289 | 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] | 4290 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4291 | struct weston_compositor *compositor = shell->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4292 | struct weston_view *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4293 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4294 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4295 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4296 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4297 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4298 | shsurf->view->geometry.width = width; |
| 4299 | shsurf->view->geometry.height = height; |
| 4300 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4301 | |
| 4302 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4303 | switch (shsurf->type) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4304 | case SHELL_SURFACE_TOPLEVEL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4305 | weston_view_set_initial_position(shsurf->view, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4306 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4307 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4308 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4309 | shell_map_fullscreen(shsurf); |
| 4310 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4311 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4312 | /* use surface configure to set the geometry */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4313 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4314 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4315 | &surf_x, &surf_y, NULL, NULL); |
| 4316 | weston_view_set_position(shsurf->view, |
| 4317 | shsurf->output->x - surf_x, |
| 4318 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4319 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4320 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4321 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4322 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4323 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4324 | weston_view_set_position(shsurf->view, |
| 4325 | shsurf->view->geometry.x + sx, |
| 4326 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4327 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4328 | case SHELL_SURFACE_TRANSIENT: |
| 4329 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4330 | default: |
| 4331 | ; |
| 4332 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4333 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 4334 | /* surface stacking order, see also activate() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4335 | switch (shsurf->type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4336 | case SHELL_SURFACE_POPUP: |
| 4337 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4338 | /* TODO: Handle a parent with multiple views */ |
| 4339 | parent = get_default_view(shsurf->parent); |
| 4340 | if (parent) { |
| 4341 | wl_list_remove(&shsurf->view->layer_link); |
| 4342 | wl_list_insert(parent->layer_link.prev, |
| 4343 | &shsurf->view->layer_link); |
| 4344 | } |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4345 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4346 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 4347 | case SHELL_SURFACE_NONE: |
| 4348 | break; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4349 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4350 | case SHELL_SURFACE_TOPLEVEL: |
| 4351 | case SHELL_SURFACE_MAXIMIZED: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4352 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4353 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4354 | wl_list_remove(&shsurf->view->layer_link); |
| 4355 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4356 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4357 | } |
| 4358 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4359 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4360 | weston_view_update_transform(shsurf->view); |
| 4361 | if (shsurf->type == SHELL_SURFACE_MAXIMIZED) { |
| 4362 | shsurf->surface->output = shsurf->output; |
| 4363 | shsurf->view->output = shsurf->output; |
| 4364 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4365 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4366 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4367 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4368 | /* XXX: xwayland's using the same fields for transient type */ |
| 4369 | case SHELL_SURFACE_XWAYLAND: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4370 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4371 | if (shsurf->transient.flags == |
| 4372 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4373 | break; |
| 4374 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4375 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4376 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4377 | if (!shell->locked) { |
| 4378 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4379 | activate(shell, shsurf->surface, seat); |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4380 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4381 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4382 | case SHELL_SURFACE_POPUP: |
| 4383 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4384 | default: |
| 4385 | break; |
| 4386 | } |
| 4387 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4388 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4389 | { |
| 4390 | switch (shell->win_animation_type) { |
| 4391 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4392 | 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] | 4393 | break; |
| 4394 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4395 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4396 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4397 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4398 | default: |
| 4399 | break; |
| 4400 | } |
| 4401 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4402 | } |
| 4403 | |
| 4404 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4405 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4406 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4407 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4408 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 4409 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4410 | struct weston_view *view; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4411 | int32_t surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4412 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4413 | shsurf = get_shell_surface(surface); |
| 4414 | if (shsurf) |
| 4415 | surface_type = shsurf->type; |
| 4416 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4417 | /* TODO: |
| 4418 | * This should probably be changed to be more shell_surface |
| 4419 | * dependent |
| 4420 | */ |
| 4421 | wl_list_for_each(view, &surface->views, surface_link) |
| 4422 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4423 | |
| 4424 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4425 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 4426 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4427 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4428 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4429 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4430 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4431 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4432 | NULL, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4433 | shsurf->view->geometry.x = shsurf->output->x - surf_x; |
| 4434 | shsurf->view->geometry.y = shsurf->output->y + |
| 4435 | get_output_panel_height(shell,shsurf->output) - surf_y; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4436 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4437 | case SHELL_SURFACE_TOPLEVEL: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4438 | case SHELL_SURFACE_TRANSIENT: |
| 4439 | case SHELL_SURFACE_POPUP: |
| 4440 | case SHELL_SURFACE_XWAYLAND: |
| 4441 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4442 | default: |
| 4443 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4444 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4445 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4446 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4447 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4448 | wl_list_for_each(view, &surface->views, surface_link) |
| 4449 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4450 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4451 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4452 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4453 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4454 | } |
| 4455 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4456 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4457 | 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] | 4458 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4459 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4460 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4461 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4462 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4463 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4464 | if (!weston_surface_is_mapped(es) && |
| 4465 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4466 | remove_popup_grab(shsurf); |
| 4467 | } |
| 4468 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4469 | if (width == 0) |
| 4470 | return; |
| 4471 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4472 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4473 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4474 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4475 | type_changed = 1; |
| 4476 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4477 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4478 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4479 | map(shell, shsurf, width, height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4480 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4481 | shsurf->view->geometry.width != width || |
| 4482 | shsurf->view->geometry.height != height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4483 | float from_x, from_y; |
| 4484 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4485 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4486 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4487 | 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] | 4488 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4489 | shsurf->view->geometry.x + to_x - from_x, |
| 4490 | shsurf->view->geometry.y + to_y - from_y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4491 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4492 | } |
| 4493 | } |
| 4494 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4495 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4496 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4497 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4498 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4499 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4500 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4501 | struct desktop_shell *shell = |
| 4502 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4503 | |
| 4504 | shell->child.process.pid = 0; |
| 4505 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4506 | |
| 4507 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4508 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4509 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4510 | shell->child.deathstamp = time; |
| 4511 | shell->child.deathcount = 0; |
| 4512 | } |
| 4513 | |
| 4514 | shell->child.deathcount++; |
| 4515 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4516 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4517 | return; |
| 4518 | } |
| 4519 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4520 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4521 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4522 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4523 | } |
| 4524 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4525 | static void |
| 4526 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4527 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4528 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4529 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4530 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4531 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4532 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4533 | desktop_shell_sigchld); |
| 4534 | |
| 4535 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4536 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4540 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4541 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4542 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4543 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4544 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4545 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4546 | if (resource) |
| 4547 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4548 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4549 | } |
| 4550 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4551 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4552 | unbind_desktop_shell(struct wl_resource *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); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4555 | |
| 4556 | if (shell->locked) |
| 4557 | resume_desktop(shell); |
| 4558 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4559 | shell->child.desktop_shell = NULL; |
| 4560 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4561 | } |
| 4562 | |
| 4563 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4564 | bind_desktop_shell(struct wl_client *client, |
| 4565 | void *data, uint32_t version, uint32_t id) |
| 4566 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4567 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4568 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4569 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4570 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4571 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4572 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4573 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4574 | wl_resource_set_implementation(resource, |
| 4575 | &desktop_shell_implementation, |
| 4576 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4577 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4578 | |
| 4579 | if (version < 2) |
| 4580 | shell_fade_startup(shell); |
| 4581 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4582 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4583 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4584 | |
| 4585 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4586 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4587 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4588 | } |
| 4589 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4590 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4591 | 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] | 4592 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4593 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4594 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4595 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4596 | if (width == 0) |
| 4597 | return; |
| 4598 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4599 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4600 | if (!shell->locked) |
| 4601 | return; |
| 4602 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4603 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4604 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4605 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4606 | if (wl_list_empty(&view->layer_link)) { |
| 4607 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4608 | &view->layer_link); |
| 4609 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4610 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4611 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4612 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4617 | screensaver_set_surface(struct wl_client *client, |
| 4618 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4619 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4620 | struct wl_resource *output_resource) |
| 4621 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4622 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4623 | struct weston_surface *surface = |
| 4624 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4625 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4626 | struct weston_view *view, *next; |
| 4627 | |
| 4628 | /* Make sure we only have one view */ |
| 4629 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4630 | weston_view_destroy(view); |
| 4631 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4632 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4633 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4634 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4635 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | static const struct screensaver_interface screensaver_implementation = { |
| 4639 | screensaver_set_surface |
| 4640 | }; |
| 4641 | |
| 4642 | static void |
| 4643 | unbind_screensaver(struct wl_resource *resource) |
| 4644 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4645 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4646 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4647 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | static void |
| 4651 | bind_screensaver(struct wl_client *client, |
| 4652 | void *data, uint32_t version, uint32_t id) |
| 4653 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4654 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4655 | struct wl_resource *resource; |
| 4656 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4657 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4658 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4659 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4660 | wl_resource_set_implementation(resource, |
| 4661 | &screensaver_implementation, |
| 4662 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4663 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4664 | return; |
| 4665 | } |
| 4666 | |
| 4667 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4668 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4669 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4670 | } |
| 4671 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4672 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4673 | 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] | 4674 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4675 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4676 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4677 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4678 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4679 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4680 | if (width == 0) |
| 4681 | return; |
| 4682 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4683 | if (!weston_surface_is_mapped(surface)) { |
| 4684 | if (!shell->showing_input_panels) |
| 4685 | return; |
| 4686 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4687 | show_surface = 1; |
| 4688 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4689 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4690 | 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] | 4691 | |
| 4692 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4693 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4694 | 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] | 4695 | } else { |
Rob Bradford | bdeb5d2 | 2013-07-11 13:20:53 +0100 | [diff] [blame] | 4696 | x = ip_surface->output->x + (ip_surface->output->width - width) / 2; |
| 4697 | y = ip_surface->output->y + ip_surface->output->height - height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4698 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4699 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4700 | weston_view_configure(ip_surface->view, x, y, width, height); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4701 | |
| 4702 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4703 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4704 | &ip_surface->view->layer_link); |
| 4705 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4706 | weston_surface_damage(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4707 | 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] | 4708 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4712 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4713 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4714 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4715 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4716 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4717 | wl_list_remove(&input_panel_surface->link); |
| 4718 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4719 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4720 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4721 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4722 | free(input_panel_surface); |
| 4723 | } |
| 4724 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4725 | static struct input_panel_surface * |
| 4726 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4727 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4728 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4729 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4730 | } else { |
| 4731 | return NULL; |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | static void |
| 4736 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4737 | { |
| 4738 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4739 | struct input_panel_surface, |
| 4740 | surface_destroy_listener); |
| 4741 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4742 | if (ipsurface->resource) { |
| 4743 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4744 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4745 | destroy_input_panel_surface(ipsurface); |
| 4746 | } |
| 4747 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4748 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4749 | static struct input_panel_surface * |
| 4750 | create_input_panel_surface(struct desktop_shell *shell, |
| 4751 | struct weston_surface *surface) |
| 4752 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4753 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4754 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4755 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4756 | if (!input_panel_surface) |
| 4757 | return NULL; |
| 4758 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4759 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4760 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4761 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4762 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4763 | |
| 4764 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4765 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4766 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4767 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4768 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4769 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4770 | &input_panel_surface->surface_destroy_listener); |
| 4771 | |
| 4772 | wl_list_init(&input_panel_surface->link); |
| 4773 | |
| 4774 | return input_panel_surface; |
| 4775 | } |
| 4776 | |
| 4777 | static void |
| 4778 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4779 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4780 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4781 | uint32_t position) |
| 4782 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4783 | struct input_panel_surface *input_panel_surface = |
| 4784 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4785 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4786 | |
| 4787 | wl_list_insert(&shell->input_panel.surfaces, |
| 4788 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4789 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4790 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4791 | input_panel_surface->panel = 0; |
| 4792 | } |
| 4793 | |
| 4794 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4795 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4796 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4797 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4798 | struct input_panel_surface *input_panel_surface = |
| 4799 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4800 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4801 | |
| 4802 | wl_list_insert(&shell->input_panel.surfaces, |
| 4803 | &input_panel_surface->link); |
| 4804 | |
| 4805 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4806 | } |
| 4807 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4808 | 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] | 4809 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4810 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4811 | }; |
| 4812 | |
| 4813 | static void |
| 4814 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4815 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4816 | struct input_panel_surface *ipsurf = |
| 4817 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4818 | |
| 4819 | destroy_input_panel_surface(ipsurf); |
| 4820 | } |
| 4821 | |
| 4822 | static void |
| 4823 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4824 | struct wl_resource *resource, |
| 4825 | uint32_t id, |
| 4826 | struct wl_resource *surface_resource) |
| 4827 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4828 | struct weston_surface *surface = |
| 4829 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4830 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4831 | struct input_panel_surface *ipsurf; |
| 4832 | |
| 4833 | if (get_input_panel_surface(surface)) { |
| 4834 | wl_resource_post_error(surface_resource, |
| 4835 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4836 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4837 | return; |
| 4838 | } |
| 4839 | |
| 4840 | ipsurf = create_input_panel_surface(shell, surface); |
| 4841 | if (!ipsurf) { |
| 4842 | wl_resource_post_error(surface_resource, |
| 4843 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4844 | "surface->configure already set"); |
| 4845 | return; |
| 4846 | } |
| 4847 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4848 | ipsurf->resource = |
| 4849 | wl_resource_create(client, |
| 4850 | &wl_input_panel_surface_interface, 1, id); |
| 4851 | wl_resource_set_implementation(ipsurf->resource, |
| 4852 | &input_panel_surface_implementation, |
| 4853 | ipsurf, |
| 4854 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4855 | } |
| 4856 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4857 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4858 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4859 | }; |
| 4860 | |
| 4861 | static void |
| 4862 | unbind_input_panel(struct wl_resource *resource) |
| 4863 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4864 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4865 | |
| 4866 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | static void |
| 4870 | bind_input_panel(struct wl_client *client, |
| 4871 | void *data, uint32_t version, uint32_t id) |
| 4872 | { |
| 4873 | struct desktop_shell *shell = data; |
| 4874 | struct wl_resource *resource; |
| 4875 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4876 | resource = wl_resource_create(client, |
| 4877 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4878 | |
| 4879 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4880 | wl_resource_set_implementation(resource, |
| 4881 | &input_panel_implementation, |
| 4882 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4883 | shell->input_panel.binding = resource; |
| 4884 | return; |
| 4885 | } |
| 4886 | |
| 4887 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4888 | "interface object already bound"); |
| 4889 | wl_resource_destroy(resource); |
| 4890 | } |
| 4891 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4892 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4893 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4894 | struct weston_surface *current; |
| 4895 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4896 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4897 | }; |
| 4898 | |
| 4899 | static void |
| 4900 | switcher_next(struct switcher *switcher) |
| 4901 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4902 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4903 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4904 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4905 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4906 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4907 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 4908 | switch (get_shell_surface_type(view->surface)) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4909 | case SHELL_SURFACE_TOPLEVEL: |
| 4910 | case SHELL_SURFACE_FULLSCREEN: |
| 4911 | case SHELL_SURFACE_MAXIMIZED: |
| 4912 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4913 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4914 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4915 | next = view->surface; |
| 4916 | prev = view->surface; |
| 4917 | view->alpha = 0.25; |
| 4918 | weston_view_geometry_dirty(view); |
| 4919 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4920 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4921 | case SHELL_SURFACE_TRANSIENT: |
| 4922 | case SHELL_SURFACE_POPUP: |
| 4923 | case SHELL_SURFACE_XWAYLAND: |
| 4924 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4925 | default: |
| 4926 | break; |
| 4927 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4928 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4929 | if (is_black_surface(view->surface, NULL)) { |
| 4930 | view->alpha = 0.25; |
| 4931 | weston_view_geometry_dirty(view); |
| 4932 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4933 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | if (next == NULL) |
| 4937 | next = first; |
| 4938 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4939 | if (next == NULL) |
| 4940 | return; |
| 4941 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4942 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4943 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4944 | |
| 4945 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4946 | wl_list_for_each(view, &next->views, surface_link) |
| 4947 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4948 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4949 | shsurf = get_shell_surface(switcher->current); |
| 4950 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4951 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4952 | } |
| 4953 | |
| 4954 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4955 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4956 | { |
| 4957 | struct switcher *switcher = |
| 4958 | container_of(listener, struct switcher, listener); |
| 4959 | |
| 4960 | switcher_next(switcher); |
| 4961 | } |
| 4962 | |
| 4963 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4964 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4965 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4966 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4967 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4968 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4969 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4970 | 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] | 4971 | if (is_focus_view(view)) |
| 4972 | continue; |
| 4973 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4974 | view->alpha = 1.0; |
| 4975 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4976 | } |
| 4977 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4978 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4979 | activate(switcher->shell, switcher->current, |
| 4980 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4981 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4982 | weston_keyboard_end_grab(keyboard); |
| 4983 | if (keyboard->input_method_resource) |
| 4984 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4985 | free(switcher); |
| 4986 | } |
| 4987 | |
| 4988 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4989 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4990 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4991 | { |
| 4992 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4993 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4994 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4995 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4996 | switcher_next(switcher); |
| 4997 | } |
| 4998 | |
| 4999 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5000 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5001 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5002 | uint32_t mods_locked, uint32_t group) |
| 5003 | { |
| 5004 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5005 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5006 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5007 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5008 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5009 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5010 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5011 | static void |
| 5012 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5013 | { |
| 5014 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5015 | |
| 5016 | switcher_destroy(switcher); |
| 5017 | } |
| 5018 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5019 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5020 | switcher_key, |
| 5021 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5022 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5023 | }; |
| 5024 | |
| 5025 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5026 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5027 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5028 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5029 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5030 | struct switcher *switcher; |
| 5031 | |
| 5032 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5033 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5034 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5035 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5036 | wl_list_init(&switcher->listener.link); |
| 5037 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5038 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5039 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5040 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5041 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5042 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5043 | switcher_next(switcher); |
| 5044 | } |
| 5045 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5046 | struct exposay_surface { |
| 5047 | struct desktop_shell *shell; |
| 5048 | struct weston_surface *surface; |
| 5049 | struct weston_view *view; |
| 5050 | struct wl_list link; |
| 5051 | |
| 5052 | int x; |
| 5053 | int y; |
| 5054 | int width; |
| 5055 | int height; |
| 5056 | double scale; |
| 5057 | |
| 5058 | int row; |
| 5059 | int column; |
| 5060 | |
| 5061 | /* The animations only apply a transformation for their own lifetime, |
| 5062 | * and don't have an option to indefinitely maintain the |
| 5063 | * transformation in a steady state - so, we apply our own once the |
| 5064 | * animation has finished. */ |
| 5065 | struct weston_transform transform; |
| 5066 | }; |
| 5067 | |
| 5068 | static void exposay_set_state(struct desktop_shell *shell, |
| 5069 | enum exposay_target_state state, |
| 5070 | struct weston_seat *seat); |
| 5071 | static void exposay_check_state(struct desktop_shell *shell); |
| 5072 | |
| 5073 | static void |
| 5074 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 5075 | { |
| 5076 | shell->exposay.in_flight++; |
| 5077 | } |
| 5078 | |
| 5079 | static void |
| 5080 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5081 | { |
| 5082 | if (--shell->exposay.in_flight > 0) |
| 5083 | return; |
| 5084 | |
| 5085 | exposay_check_state(shell); |
| 5086 | } |
| 5087 | |
| 5088 | static void |
| 5089 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5090 | { |
| 5091 | struct exposay_surface *esurface = data; |
| 5092 | |
| 5093 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5094 | &esurface->transform.link); |
| 5095 | weston_matrix_init(&esurface->transform.matrix); |
| 5096 | weston_matrix_scale(&esurface->transform.matrix, |
| 5097 | esurface->scale, esurface->scale, 1.0f); |
| 5098 | weston_matrix_translate(&esurface->transform.matrix, |
| 5099 | esurface->x - esurface->view->geometry.x, |
| 5100 | esurface->y - esurface->view->geometry.y, |
| 5101 | 0); |
| 5102 | |
| 5103 | weston_view_geometry_dirty(esurface->view); |
| 5104 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5105 | |
| 5106 | exposay_in_flight_dec(esurface->shell); |
| 5107 | } |
| 5108 | |
| 5109 | static void |
| 5110 | exposay_animate_in(struct exposay_surface *esurface) |
| 5111 | { |
| 5112 | exposay_in_flight_inc(esurface->shell); |
| 5113 | |
| 5114 | weston_move_scale_run(esurface->view, |
| 5115 | esurface->x - esurface->view->geometry.x, |
| 5116 | esurface->y - esurface->view->geometry.y, |
| 5117 | 1.0, esurface->scale, 0, |
| 5118 | exposay_animate_in_done, esurface); |
| 5119 | } |
| 5120 | |
| 5121 | static void |
| 5122 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5123 | { |
| 5124 | struct exposay_surface *esurface = data; |
| 5125 | struct desktop_shell *shell = esurface->shell; |
| 5126 | |
| 5127 | wl_list_remove(&esurface->link); |
| 5128 | free(esurface); |
| 5129 | |
| 5130 | exposay_in_flight_dec(shell); |
| 5131 | } |
| 5132 | |
| 5133 | static void |
| 5134 | exposay_animate_out(struct exposay_surface *esurface) |
| 5135 | { |
| 5136 | exposay_in_flight_inc(esurface->shell); |
| 5137 | |
| 5138 | /* Remove the static transformation set up by |
| 5139 | * exposay_transform_in_done(). */ |
| 5140 | wl_list_remove(&esurface->transform.link); |
| 5141 | weston_view_geometry_dirty(esurface->view); |
| 5142 | |
| 5143 | weston_move_scale_run(esurface->view, |
| 5144 | esurface->x - esurface->view->geometry.x, |
| 5145 | esurface->y - esurface->view->geometry.y, |
| 5146 | 1.0, esurface->scale, 1, |
| 5147 | exposay_animate_out_done, esurface); |
| 5148 | } |
| 5149 | |
| 5150 | static void |
| 5151 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5152 | struct exposay_surface *esurface) |
| 5153 | { |
| 5154 | struct weston_view *view = NULL; |
| 5155 | |
| 5156 | if (esurface) { |
| 5157 | shell->exposay.row_current = esurface->row; |
| 5158 | shell->exposay.column_current = esurface->column; |
| 5159 | view = esurface->view; |
| 5160 | } |
| 5161 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5162 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5163 | shell->exposay.focus_current = view; |
| 5164 | } |
| 5165 | |
| 5166 | static int |
| 5167 | exposay_is_animating(struct desktop_shell *shell) |
| 5168 | { |
| 5169 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5170 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5171 | return 0; |
| 5172 | |
| 5173 | return (shell->exposay.in_flight > 0); |
| 5174 | } |
| 5175 | |
| 5176 | static void |
| 5177 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5178 | { |
| 5179 | struct exposay_surface *esurface; |
| 5180 | |
| 5181 | if (exposay_is_animating(shell)) |
| 5182 | return; |
| 5183 | |
| 5184 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5185 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5186 | continue; |
| 5187 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5188 | continue; |
| 5189 | |
| 5190 | exposay_highlight_surface(shell, esurface); |
| 5191 | return; |
| 5192 | } |
| 5193 | } |
| 5194 | |
| 5195 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5196 | * aspect ratio into account really. Also needs to be notified of surface |
| 5197 | * addition and removal and adjust layout/animate accordingly. */ |
| 5198 | static enum exposay_layout_state |
| 5199 | exposay_layout(struct desktop_shell *shell) |
| 5200 | { |
| 5201 | struct workspace *workspace = shell->exposay.workspace; |
| 5202 | struct weston_compositor *compositor = shell->compositor; |
| 5203 | struct weston_output *output = get_default_output(compositor); |
| 5204 | struct weston_view *view; |
| 5205 | struct exposay_surface *esurface; |
| 5206 | int w, h; |
| 5207 | int i; |
| 5208 | int last_row_removed = 0; |
| 5209 | |
| 5210 | wl_list_init(&shell->exposay.surface_list); |
| 5211 | |
| 5212 | shell->exposay.num_surfaces = 0; |
| 5213 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5214 | if (!get_shell_surface(view->surface)) |
| 5215 | continue; |
| 5216 | shell->exposay.num_surfaces++; |
| 5217 | } |
| 5218 | |
| 5219 | if (shell->exposay.num_surfaces == 0) { |
| 5220 | shell->exposay.grid_size = 0; |
| 5221 | shell->exposay.hpadding_outer = 0; |
| 5222 | shell->exposay.vpadding_outer = 0; |
| 5223 | shell->exposay.padding_inner = 0; |
| 5224 | shell->exposay.surface_size = 0; |
| 5225 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5226 | } |
| 5227 | |
| 5228 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5229 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5230 | * around the outside and 80px internal padding between surfaces, and |
| 5231 | * maximise the area made available to surfaces after this, but only |
| 5232 | * to a maximum of 1/3rd the total output size. |
| 5233 | * |
| 5234 | * If we can't make a square grid, add one extra row at the bottom |
| 5235 | * which will have a smaller number of columns. |
| 5236 | * |
| 5237 | * XXX: Surely there has to be a better way to express this maths, |
| 5238 | * right?! |
| 5239 | */ |
| 5240 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5241 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5242 | shell->exposay.grid_size++; |
| 5243 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5244 | |
| 5245 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5246 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5247 | shell->exposay.padding_inner = 80; |
| 5248 | |
| 5249 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5250 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5251 | w /= shell->exposay.grid_size; |
| 5252 | |
| 5253 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5254 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5255 | h /= shell->exposay.grid_size; |
| 5256 | |
| 5257 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5258 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5259 | shell->exposay.surface_size = output->width / 2; |
| 5260 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5261 | shell->exposay.surface_size = output->height / 2; |
| 5262 | |
| 5263 | i = 0; |
| 5264 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5265 | int pad; |
| 5266 | |
| 5267 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5268 | |
| 5269 | if (!get_shell_surface(view->surface)) |
| 5270 | continue; |
| 5271 | |
| 5272 | esurface = malloc(sizeof(*esurface)); |
| 5273 | if (!esurface) { |
| 5274 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5275 | shell->exposay.seat); |
| 5276 | break; |
| 5277 | } |
| 5278 | |
| 5279 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5280 | esurface->shell = shell; |
| 5281 | esurface->view = view; |
| 5282 | |
| 5283 | esurface->row = i / shell->exposay.grid_size; |
| 5284 | esurface->column = i % shell->exposay.grid_size; |
| 5285 | |
| 5286 | esurface->x = shell->exposay.hpadding_outer; |
| 5287 | esurface->x += pad * esurface->column; |
| 5288 | esurface->y = shell->exposay.vpadding_outer; |
| 5289 | esurface->y += pad * esurface->row; |
| 5290 | |
| 5291 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5292 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5293 | |
| 5294 | if (view->geometry.width > view->geometry.height) |
| 5295 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.width; |
| 5296 | else |
| 5297 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.height; |
| 5298 | esurface->width = view->geometry.width * esurface->scale; |
| 5299 | esurface->height = view->geometry.height * esurface->scale; |
| 5300 | |
| 5301 | if (shell->exposay.focus_current == esurface->view) |
| 5302 | exposay_highlight_surface(shell, esurface); |
| 5303 | |
| 5304 | exposay_animate_in(esurface); |
| 5305 | |
| 5306 | i++; |
| 5307 | } |
| 5308 | |
| 5309 | weston_compositor_schedule_repaint(shell->compositor); |
| 5310 | |
| 5311 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5312 | } |
| 5313 | |
| 5314 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5315 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 5316 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5317 | { |
| 5318 | struct desktop_shell *shell = |
| 5319 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5320 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5321 | weston_pointer_move(grab->pointer, x, y); |
| 5322 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5323 | exposay_pick(shell, |
| 5324 | wl_fixed_to_int(grab->pointer->x), |
| 5325 | wl_fixed_to_int(grab->pointer->y)); |
| 5326 | } |
| 5327 | |
| 5328 | static void |
| 5329 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5330 | uint32_t state_w) |
| 5331 | { |
| 5332 | struct desktop_shell *shell = |
| 5333 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5334 | struct weston_seat *seat = grab->pointer->seat; |
| 5335 | enum wl_pointer_button_state state = state_w; |
| 5336 | |
| 5337 | if (button != BTN_LEFT) |
| 5338 | return; |
| 5339 | |
| 5340 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5341 | * releasing on a different surface. */ |
| 5342 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5343 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5344 | return; |
| 5345 | } |
| 5346 | |
| 5347 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5348 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5349 | else |
| 5350 | shell->exposay.clicked = NULL; |
| 5351 | } |
| 5352 | |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5353 | static void |
| 5354 | exposay_pointer_grab_cancel(struct weston_pointer_grab *grab) |
| 5355 | { |
| 5356 | struct desktop_shell *shell = |
| 5357 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5358 | |
| 5359 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5360 | } |
| 5361 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5362 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5363 | noop_grab_focus, |
| 5364 | exposay_motion, |
| 5365 | exposay_button, |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5366 | exposay_pointer_grab_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5367 | }; |
| 5368 | |
| 5369 | static int |
| 5370 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5371 | { |
| 5372 | struct exposay_surface *esurface; |
| 5373 | |
| 5374 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5375 | if (esurface->row != row || esurface->column != column) |
| 5376 | continue; |
| 5377 | |
| 5378 | exposay_highlight_surface(shell, esurface); |
| 5379 | return 1; |
| 5380 | } |
| 5381 | |
| 5382 | return 0; |
| 5383 | } |
| 5384 | |
| 5385 | static void |
| 5386 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5387 | uint32_t state_w) |
| 5388 | { |
| 5389 | struct weston_seat *seat = grab->keyboard->seat; |
| 5390 | struct desktop_shell *shell = |
| 5391 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5392 | enum wl_keyboard_key_state state = state_w; |
| 5393 | |
| 5394 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5395 | return; |
| 5396 | |
| 5397 | switch (key) { |
| 5398 | case KEY_ESC: |
| 5399 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5400 | break; |
| 5401 | case KEY_ENTER: |
| 5402 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5403 | break; |
| 5404 | case KEY_UP: |
| 5405 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5406 | shell->exposay.column_current); |
| 5407 | break; |
| 5408 | case KEY_DOWN: |
| 5409 | /* Special case for trying to move to the bottom row when it |
| 5410 | * has fewer items than all the others. */ |
| 5411 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5412 | shell->exposay.column_current) && |
| 5413 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5414 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5415 | (shell->exposay.num_surfaces % |
| 5416 | shell->exposay.grid_size) - 1); |
| 5417 | } |
| 5418 | break; |
| 5419 | case KEY_LEFT: |
| 5420 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5421 | shell->exposay.column_current - 1); |
| 5422 | break; |
| 5423 | case KEY_RIGHT: |
| 5424 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5425 | shell->exposay.column_current + 1); |
| 5426 | break; |
| 5427 | case KEY_TAB: |
| 5428 | /* Try to move right, then down (and to the leftmost column), |
| 5429 | * then if all else fails, to the top left. */ |
| 5430 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5431 | shell->exposay.column_current + 1) && |
| 5432 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5433 | exposay_maybe_move(shell, 0, 0); |
| 5434 | break; |
| 5435 | default: |
| 5436 | break; |
| 5437 | } |
| 5438 | } |
| 5439 | |
| 5440 | static void |
| 5441 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5442 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5443 | uint32_t mods_locked, uint32_t group) |
| 5444 | { |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5445 | struct desktop_shell *shell = |
| 5446 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5447 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 5448 | |
| 5449 | /* We want to know when mod has been pressed and released. |
| 5450 | * FIXME: There is a problem here: if mod is pressed, then a key |
| 5451 | * is pressed and released, then mod is released, we will treat that |
| 5452 | * as if only mod had been pressed and released. */ |
| 5453 | if (seat->modifier_state) { |
| 5454 | if (seat->modifier_state == shell->binding_modifier) { |
| 5455 | shell->exposay.mod_pressed = true; |
| 5456 | } else { |
| 5457 | shell->exposay.mod_invalid = true; |
| 5458 | } |
| 5459 | } else { |
| 5460 | if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid) |
| 5461 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5462 | |
| 5463 | shell->exposay.mod_invalid = false; |
| 5464 | shell->exposay.mod_pressed = false; |
| 5465 | } |
| 5466 | |
| 5467 | return; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5468 | } |
| 5469 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5470 | static void |
| 5471 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 5472 | { |
| 5473 | struct desktop_shell *shell = |
| 5474 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5475 | |
| 5476 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5477 | } |
| 5478 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5479 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5480 | exposay_key, |
| 5481 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5482 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5483 | }; |
| 5484 | |
| 5485 | /** |
| 5486 | * Called when the transition from overview -> inactive has completed. |
| 5487 | */ |
| 5488 | static enum exposay_layout_state |
| 5489 | exposay_set_inactive(struct desktop_shell *shell) |
| 5490 | { |
| 5491 | struct weston_seat *seat = shell->exposay.seat; |
| 5492 | |
| 5493 | weston_keyboard_end_grab(seat->keyboard); |
| 5494 | weston_pointer_end_grab(seat->pointer); |
| 5495 | if (seat->keyboard->input_method_resource) |
| 5496 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5497 | |
| 5498 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5499 | } |
| 5500 | |
| 5501 | /** |
| 5502 | * Begins the transition from overview to inactive. */ |
| 5503 | static enum exposay_layout_state |
| 5504 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5505 | { |
| 5506 | struct exposay_surface *esurface; |
| 5507 | |
| 5508 | /* Call activate() before we start the animations to avoid |
| 5509 | * animating back the old state and then immediately transitioning |
| 5510 | * to the new. */ |
| 5511 | if (switch_focus && shell->exposay.focus_current) |
| 5512 | activate(shell, shell->exposay.focus_current->surface, |
| 5513 | shell->exposay.seat); |
| 5514 | else if (shell->exposay.focus_prev) |
| 5515 | activate(shell, shell->exposay.focus_prev->surface, |
| 5516 | shell->exposay.seat); |
| 5517 | |
| 5518 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5519 | exposay_animate_out(esurface); |
| 5520 | weston_compositor_schedule_repaint(shell->compositor); |
| 5521 | |
| 5522 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5523 | } |
| 5524 | |
| 5525 | static enum exposay_layout_state |
| 5526 | exposay_transition_active(struct desktop_shell *shell) |
| 5527 | { |
| 5528 | struct weston_seat *seat = shell->exposay.seat; |
| 5529 | |
| 5530 | shell->exposay.workspace = get_current_workspace(shell); |
| 5531 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5532 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5533 | shell->exposay.clicked = NULL; |
| 5534 | wl_list_init(&shell->exposay.surface_list); |
| 5535 | |
| 5536 | lower_fullscreen_layer(shell); |
| 5537 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5538 | weston_keyboard_start_grab(seat->keyboard, |
| 5539 | &shell->exposay.grab_kbd); |
| 5540 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5541 | |
| 5542 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5543 | weston_pointer_start_grab(seat->pointer, |
| 5544 | &shell->exposay.grab_ptr); |
| 5545 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5546 | seat->pointer->x, seat->pointer->y); |
| 5547 | |
| 5548 | return exposay_layout(shell); |
| 5549 | } |
| 5550 | |
| 5551 | static void |
| 5552 | exposay_check_state(struct desktop_shell *shell) |
| 5553 | { |
| 5554 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5555 | int do_switch = 0; |
| 5556 | |
| 5557 | /* Don't do anything whilst animations are running, just store up |
| 5558 | * target state changes and only act on them when the animations have |
| 5559 | * completed. */ |
| 5560 | if (exposay_is_animating(shell)) |
| 5561 | return; |
| 5562 | |
| 5563 | switch (shell->exposay.state_target) { |
| 5564 | case EXPOSAY_TARGET_OVERVIEW: |
| 5565 | switch (shell->exposay.state_cur) { |
| 5566 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5567 | goto out; |
| 5568 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5569 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5570 | break; |
| 5571 | default: |
| 5572 | state_new = exposay_transition_active(shell); |
| 5573 | break; |
| 5574 | } |
| 5575 | break; |
| 5576 | |
| 5577 | case EXPOSAY_TARGET_SWITCH: |
| 5578 | do_switch = 1; /* fallthrough */ |
| 5579 | case EXPOSAY_TARGET_CANCEL: |
| 5580 | switch (shell->exposay.state_cur) { |
| 5581 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5582 | goto out; |
| 5583 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5584 | state_new = exposay_set_inactive(shell); |
| 5585 | break; |
| 5586 | default: |
| 5587 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5588 | break; |
| 5589 | } |
| 5590 | |
| 5591 | break; |
| 5592 | } |
| 5593 | |
| 5594 | out: |
| 5595 | shell->exposay.state_cur = state_new; |
| 5596 | } |
| 5597 | |
| 5598 | static void |
| 5599 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5600 | struct weston_seat *seat) |
| 5601 | { |
| 5602 | shell->exposay.state_target = state; |
| 5603 | shell->exposay.seat = seat; |
| 5604 | exposay_check_state(shell); |
| 5605 | } |
| 5606 | |
| 5607 | static void |
| 5608 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5609 | void *data) |
| 5610 | { |
| 5611 | struct desktop_shell *shell = data; |
| 5612 | |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5613 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5614 | } |
| 5615 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5616 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5617 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5618 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5619 | { |
| 5620 | struct weston_compositor *compositor = data; |
| 5621 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5622 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5623 | |
| 5624 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5625 | * control on the primary display. We'd have to extend later if we |
| 5626 | * ever get support for setting backlights on random desktop LCD |
| 5627 | * panels though */ |
| 5628 | output = get_default_output(compositor); |
| 5629 | if (!output) |
| 5630 | return; |
| 5631 | |
| 5632 | if (!output->set_backlight) |
| 5633 | return; |
| 5634 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5635 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5636 | backlight_new = output->backlight_current - 25; |
| 5637 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5638 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5639 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5640 | if (backlight_new < 5) |
| 5641 | backlight_new = 5; |
| 5642 | if (backlight_new > 255) |
| 5643 | backlight_new = 255; |
| 5644 | |
| 5645 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5646 | output->set_backlight(output, output->backlight_current); |
| 5647 | } |
| 5648 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5649 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5650 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5651 | struct weston_seat *seat; |
| 5652 | uint32_t key[2]; |
| 5653 | int key_released[2]; |
| 5654 | }; |
| 5655 | |
| 5656 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5657 | 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] | 5658 | uint32_t key, uint32_t state) |
| 5659 | { |
| 5660 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5661 | struct weston_compositor *ec = db->seat->compositor; |
| 5662 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5663 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5664 | uint32_t serial; |
| 5665 | int send = 0, terminate = 0; |
| 5666 | int check_binding = 1; |
| 5667 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5668 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5669 | |
| 5670 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5671 | /* Do not run bindings on key releases */ |
| 5672 | check_binding = 0; |
| 5673 | |
| 5674 | for (i = 0; i < 2; i++) |
| 5675 | if (key == db->key[i]) |
| 5676 | db->key_released[i] = 1; |
| 5677 | |
| 5678 | if (db->key_released[0] && db->key_released[1]) { |
| 5679 | /* All key releases been swalled so end the grab */ |
| 5680 | terminate = 1; |
| 5681 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5682 | /* Should not swallow release of other keys */ |
| 5683 | send = 1; |
| 5684 | } |
| 5685 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5686 | /* Do not check bindings for the first press of the binding |
| 5687 | * key. This allows it to be used as a debug shortcut. |
| 5688 | * We still need to swallow this event. */ |
| 5689 | check_binding = 0; |
| 5690 | } else if (db->key[1]) { |
| 5691 | /* If we already ran a binding don't process another one since |
| 5692 | * we can't keep track of all the binding keys that were |
| 5693 | * pressed in order to swallow the release events. */ |
| 5694 | send = 1; |
| 5695 | check_binding = 0; |
| 5696 | } |
| 5697 | |
| 5698 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5699 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5700 | key, state)) { |
| 5701 | /* We ran a binding so swallow the press and keep the |
| 5702 | * grab to swallow the released too. */ |
| 5703 | send = 0; |
| 5704 | terminate = 0; |
| 5705 | db->key[1] = key; |
| 5706 | } else { |
| 5707 | /* Terminate the grab since the key pressed is not a |
| 5708 | * debug binding key. */ |
| 5709 | send = 1; |
| 5710 | terminate = 1; |
| 5711 | } |
| 5712 | } |
| 5713 | |
| 5714 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5715 | serial = wl_display_next_serial(display); |
| 5716 | resource_list = &grab->keyboard->focus_resource_list; |
| 5717 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5718 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5719 | } |
| 5720 | } |
| 5721 | |
| 5722 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5723 | weston_keyboard_end_grab(grab->keyboard); |
| 5724 | if (grab->keyboard->input_method_resource) |
| 5725 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5726 | free(db); |
| 5727 | } |
| 5728 | } |
| 5729 | |
| 5730 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5731 | 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] | 5732 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5733 | uint32_t mods_locked, uint32_t group) |
| 5734 | { |
| 5735 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5736 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5737 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5738 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5739 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5740 | wl_resource_for_each(resource, resource_list) { |
| 5741 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5742 | mods_latched, mods_locked, group); |
| 5743 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5744 | } |
| 5745 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5746 | static void |
| 5747 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5748 | { |
| 5749 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5750 | |
| 5751 | weston_keyboard_end_grab(grab->keyboard); |
| 5752 | free(db); |
| 5753 | } |
| 5754 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5755 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5756 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5757 | debug_binding_modifiers, |
| 5758 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5759 | }; |
| 5760 | |
| 5761 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5762 | 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] | 5763 | { |
| 5764 | struct debug_binding_grab *grab; |
| 5765 | |
| 5766 | grab = calloc(1, sizeof *grab); |
| 5767 | if (!grab) |
| 5768 | return; |
| 5769 | |
| 5770 | grab->seat = (struct weston_seat *) seat; |
| 5771 | grab->key[0] = key; |
| 5772 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5773 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5774 | } |
| 5775 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5776 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5777 | 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] | 5778 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5779 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5780 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5781 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5782 | struct desktop_shell *shell = data; |
| 5783 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5784 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5785 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5786 | focus_surface = seat->keyboard->focus; |
| 5787 | if (!focus_surface) |
| 5788 | return; |
| 5789 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5790 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5791 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5792 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5793 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5794 | |
| 5795 | /* Skip clients that we launched ourselves (the credentials of |
| 5796 | * the socketpair is ours) */ |
| 5797 | if (pid == getpid()) |
| 5798 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5799 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5800 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5804 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5805 | uint32_t key, void *data) |
| 5806 | { |
| 5807 | struct desktop_shell *shell = data; |
| 5808 | unsigned int new_index = shell->workspaces.current; |
| 5809 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5810 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5811 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5812 | if (new_index != 0) |
| 5813 | new_index--; |
| 5814 | |
| 5815 | change_workspace(shell, new_index); |
| 5816 | } |
| 5817 | |
| 5818 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5819 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5820 | uint32_t key, void *data) |
| 5821 | { |
| 5822 | struct desktop_shell *shell = data; |
| 5823 | unsigned int new_index = shell->workspaces.current; |
| 5824 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5825 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5826 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5827 | if (new_index < shell->workspaces.num - 1) |
| 5828 | new_index++; |
| 5829 | |
| 5830 | change_workspace(shell, new_index); |
| 5831 | } |
| 5832 | |
| 5833 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5834 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5835 | uint32_t key, void *data) |
| 5836 | { |
| 5837 | struct desktop_shell *shell = data; |
| 5838 | unsigned int new_index; |
| 5839 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5840 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5841 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5842 | new_index = key - KEY_F1; |
| 5843 | if (new_index >= shell->workspaces.num) |
| 5844 | new_index = shell->workspaces.num - 1; |
| 5845 | |
| 5846 | change_workspace(shell, new_index); |
| 5847 | } |
| 5848 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5849 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5850 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5851 | uint32_t key, void *data) |
| 5852 | { |
| 5853 | struct desktop_shell *shell = data; |
| 5854 | unsigned int new_index = shell->workspaces.current; |
| 5855 | |
| 5856 | if (shell->locked) |
| 5857 | return; |
| 5858 | |
| 5859 | if (new_index != 0) |
| 5860 | new_index--; |
| 5861 | |
| 5862 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5863 | } |
| 5864 | |
| 5865 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5866 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5867 | uint32_t key, void *data) |
| 5868 | { |
| 5869 | struct desktop_shell *shell = data; |
| 5870 | unsigned int new_index = shell->workspaces.current; |
| 5871 | |
| 5872 | if (shell->locked) |
| 5873 | return; |
| 5874 | |
| 5875 | if (new_index < shell->workspaces.num - 1) |
| 5876 | new_index++; |
| 5877 | |
| 5878 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5879 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5880 | |
| 5881 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5882 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5883 | { |
| 5884 | struct shell_output *output_listener = |
| 5885 | container_of(listener, struct shell_output, destroy_listener); |
| 5886 | |
| 5887 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5888 | wl_list_remove(&output_listener->link); |
| 5889 | free(output_listener); |
| 5890 | } |
| 5891 | |
| 5892 | static void |
| 5893 | create_shell_output(struct desktop_shell *shell, |
| 5894 | struct weston_output *output) |
| 5895 | { |
| 5896 | struct shell_output *shell_output; |
| 5897 | |
| 5898 | shell_output = zalloc(sizeof *shell_output); |
| 5899 | if (shell_output == NULL) |
| 5900 | return; |
| 5901 | |
| 5902 | shell_output->output = output; |
| 5903 | shell_output->shell = shell; |
| 5904 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5905 | wl_signal_add(&output->destroy_signal, |
| 5906 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5907 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | static void |
| 5911 | handle_output_create(struct wl_listener *listener, void *data) |
| 5912 | { |
| 5913 | struct desktop_shell *shell = |
| 5914 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5915 | struct weston_output *output = (struct weston_output *)data; |
| 5916 | |
| 5917 | create_shell_output(shell, output); |
| 5918 | } |
| 5919 | |
| 5920 | static void |
| 5921 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5922 | struct desktop_shell *shell) |
| 5923 | { |
| 5924 | struct weston_output *output; |
| 5925 | |
| 5926 | wl_list_init(&shell->output_list); |
| 5927 | wl_list_for_each(output, &ec->output_list, link) |
| 5928 | create_shell_output(shell, output); |
| 5929 | |
| 5930 | shell->output_create_listener.notify = handle_output_create; |
| 5931 | wl_signal_add(&ec->output_created_signal, |
| 5932 | &shell->output_create_listener); |
| 5933 | } |
| 5934 | |
| 5935 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5936 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5937 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5938 | struct desktop_shell *shell = |
| 5939 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5940 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5941 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5942 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5943 | if (shell->child.client) |
| 5944 | wl_client_destroy(shell->child.client); |
| 5945 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5946 | wl_list_remove(&shell->idle_listener.link); |
| 5947 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5948 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 5949 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5950 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5951 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5952 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5953 | wl_list_remove(&shell_output->link); |
| 5954 | free(shell_output); |
| 5955 | } |
| 5956 | |
| 5957 | wl_list_remove(&shell->output_create_listener.link); |
| 5958 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5959 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5960 | workspace_destroy(*ws); |
| 5961 | wl_array_release(&shell->workspaces.array); |
| 5962 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5963 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5964 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5965 | free(shell); |
| 5966 | } |
| 5967 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5968 | static void |
| 5969 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5970 | { |
| 5971 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5972 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5973 | |
| 5974 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5975 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5976 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5977 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 5978 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 5979 | MODIFIER_ALT, |
| 5980 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5981 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5982 | click_to_activate_binding, |
| 5983 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5984 | weston_compositor_add_touch_binding(ec, 0, |
| 5985 | touch_to_activate_binding, |
| 5986 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5987 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5988 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5989 | surface_opacity_binding, NULL); |
| 5990 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5991 | MODIFIER_SUPER, zoom_axis_binding, |
| 5992 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5993 | |
| 5994 | /* configurable bindings */ |
| 5995 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5996 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5997 | zoom_key_binding, NULL); |
| 5998 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5999 | zoom_key_binding, NULL); |
| 6000 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6001 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6002 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6003 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6004 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6005 | |
| 6006 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6007 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6008 | rotate_binding, NULL); |
| 6009 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6010 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6011 | shell); |
| 6012 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6013 | ec); |
| 6014 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6015 | backlight_binding, ec); |
| 6016 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6017 | ec); |
| 6018 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6019 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6020 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6021 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6022 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6023 | workspace_up_binding, shell); |
| 6024 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6025 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6026 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6027 | workspace_move_surface_up_binding, |
| 6028 | shell); |
| 6029 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6030 | workspace_move_surface_down_binding, |
| 6031 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6032 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6033 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 6034 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6035 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6036 | if (shell->workspaces.num > 1) { |
| 6037 | num_workspace_bindings = shell->workspaces.num; |
| 6038 | if (num_workspace_bindings > 6) |
| 6039 | num_workspace_bindings = 6; |
| 6040 | for (i = 0; i < num_workspace_bindings; i++) |
| 6041 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6042 | workspace_f_binding, |
| 6043 | shell); |
| 6044 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6045 | |
| 6046 | /* Debug bindings */ |
| 6047 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6048 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6049 | } |
| 6050 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6051 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6052 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6053 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6054 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6055 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6056 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6057 | struct workspace **pws; |
| 6058 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6059 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6060 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6061 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6062 | if (shell == NULL) |
| 6063 | return -1; |
| 6064 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6065 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6066 | |
| 6067 | shell->destroy_listener.notify = shell_destroy; |
| 6068 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6069 | shell->idle_listener.notify = idle_handler; |
| 6070 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6071 | shell->wake_listener.notify = wake_handler; |
| 6072 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6073 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6074 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6075 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6076 | 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] | 6077 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6078 | 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] | 6079 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6080 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6081 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6082 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6083 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6084 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6085 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6086 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6087 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6088 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6089 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6090 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6091 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6092 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6093 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6094 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6095 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6096 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6097 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6098 | |
| 6099 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6100 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6101 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6102 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6103 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6104 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6105 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6106 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6107 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6108 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6109 | if (pws == NULL) |
| 6110 | return -1; |
| 6111 | |
| 6112 | *pws = workspace_create(); |
| 6113 | if (*pws == NULL) |
| 6114 | return -1; |
| 6115 | } |
| 6116 | activate_workspace(shell, 0); |
| 6117 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6118 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6119 | wl_list_init(&shell->workspaces.animation.link); |
| 6120 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6121 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6122 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6123 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6124 | return -1; |
| 6125 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6126 | if (wl_global_create(ec->wl_display, |
| 6127 | &desktop_shell_interface, 2, |
| 6128 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6129 | return -1; |
| 6130 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6131 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6132 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6133 | return -1; |
| 6134 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6135 | 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] | 6136 | shell, bind_input_panel) == NULL) |
| 6137 | return -1; |
| 6138 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6139 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6140 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6141 | return -1; |
| 6142 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6143 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6144 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6145 | setup_output_destroy_handler(ec, shell); |
| 6146 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6147 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6148 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6149 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6150 | shell->screensaver.timer = |
| 6151 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6152 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6153 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6154 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6155 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6156 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6157 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6158 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6159 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6160 | return 0; |
| 6161 | } |