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; |
| 223 | } exposay; |
| 224 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 225 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 226 | enum animation_type win_animation_type; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 227 | enum animation_type startup_animation_type; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 228 | enum animation_type focus_animation_type; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 229 | |
| 230 | struct wl_listener output_create_listener; |
| 231 | struct wl_list output_list; |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame^] | 232 | |
| 233 | char *client; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 234 | }; |
| 235 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 236 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 237 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 238 | SHELL_SURFACE_TOPLEVEL, |
| 239 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 240 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 241 | SHELL_SURFACE_MAXIMIZED, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 242 | SHELL_SURFACE_POPUP, |
| 243 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 244 | }; |
| 245 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 246 | struct ping_timer { |
| 247 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 248 | uint32_t serial; |
| 249 | }; |
| 250 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 251 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 252 | struct wl_resource *resource; |
| 253 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 254 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 255 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 256 | struct weston_view *view; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 257 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 258 | struct weston_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 259 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 260 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 261 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 262 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 263 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 264 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 265 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 266 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 267 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 268 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 269 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 270 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 271 | } rotation; |
| 272 | |
| 273 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 274 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 275 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 276 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 277 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 278 | } popup; |
| 279 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 280 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 281 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 282 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 283 | } transient; |
| 284 | |
| 285 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 286 | enum wl_shell_surface_fullscreen_method type; |
| 287 | struct weston_transform transform; /* matrix from x, y */ |
| 288 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 289 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 290 | } fullscreen; |
| 291 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 292 | struct ping_timer *ping_timer; |
| 293 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 294 | struct weston_transform workspace_transform; |
| 295 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 296 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 297 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 298 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 299 | |
| 300 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 301 | }; |
| 302 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 303 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 304 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 305 | struct shell_surface *shsurf; |
| 306 | struct wl_listener shsurf_destroy_listener; |
| 307 | }; |
| 308 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 309 | struct shell_touch_grab { |
| 310 | struct weston_touch_grab grab; |
| 311 | struct shell_surface *shsurf; |
| 312 | struct wl_listener shsurf_destroy_listener; |
| 313 | struct weston_touch *touch; |
| 314 | }; |
| 315 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 316 | struct weston_move_grab { |
| 317 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 318 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 319 | }; |
| 320 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 321 | struct weston_touch_move_grab { |
| 322 | struct shell_touch_grab base; |
| 323 | wl_fixed_t dx, dy; |
| 324 | }; |
| 325 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 326 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 327 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 328 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 329 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 330 | float x; |
| 331 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 332 | } center; |
| 333 | }; |
| 334 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 335 | struct shell_seat { |
| 336 | struct weston_seat *seat; |
| 337 | struct wl_listener seat_destroy_listener; |
| 338 | |
| 339 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 340 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 341 | struct wl_list surfaces_list; |
| 342 | struct wl_client *client; |
| 343 | int32_t initial_up; |
| 344 | } popup_grab; |
| 345 | }; |
| 346 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 347 | static void |
| 348 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 349 | struct weston_seat *seat); |
| 350 | |
| 351 | static struct workspace * |
| 352 | get_current_workspace(struct desktop_shell *shell); |
| 353 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 354 | static struct shell_surface * |
| 355 | get_shell_surface(struct weston_surface *surface); |
| 356 | |
| 357 | static struct desktop_shell * |
| 358 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 359 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 360 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 361 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 362 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 363 | static void |
| 364 | shell_fade_startup(struct desktop_shell *shell); |
| 365 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 366 | static bool |
| 367 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 368 | { |
| 369 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 370 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 371 | |
| 372 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 373 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 374 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 375 | return false; |
| 376 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 377 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 378 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 379 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 380 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 381 | } |
| 382 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 383 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 384 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 385 | { |
| 386 | struct shell_grab *grab; |
| 387 | |
| 388 | grab = container_of(listener, struct shell_grab, |
| 389 | shsurf_destroy_listener); |
| 390 | |
| 391 | grab->shsurf = NULL; |
| 392 | } |
| 393 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 394 | static struct weston_view * |
| 395 | get_default_view(struct weston_surface *surface) |
| 396 | { |
| 397 | struct shell_surface *shsurf; |
| 398 | struct weston_view *view; |
| 399 | |
| 400 | if (!surface || wl_list_empty(&surface->views)) |
| 401 | return NULL; |
| 402 | |
| 403 | shsurf = get_shell_surface(surface); |
| 404 | if (shsurf) |
| 405 | return shsurf->view; |
| 406 | |
| 407 | wl_list_for_each(view, &surface->views, surface_link) |
| 408 | if (weston_view_is_mapped(view)) |
| 409 | return view; |
| 410 | |
| 411 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 412 | } |
| 413 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 414 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 415 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 416 | |
| 417 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 418 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 419 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 420 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 421 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 422 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 423 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 424 | struct desktop_shell *shell = shsurf->shell; |
| 425 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 426 | popup_grab_end(pointer); |
| 427 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 428 | grab->grab.interface = interface; |
| 429 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 430 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 431 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 432 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 433 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 434 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 435 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 436 | if (shell->child.desktop_shell) { |
| 437 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 438 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 439 | weston_pointer_set_focus(pointer, |
| 440 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 441 | wl_fixed_from_int(0), |
| 442 | wl_fixed_from_int(0)); |
| 443 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 447 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 448 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 449 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 450 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 451 | grab->shsurf->grabbed = 0; |
| 452 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 453 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 454 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 458 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 459 | const struct weston_touch_grab_interface *interface, |
| 460 | struct shell_surface *shsurf, |
| 461 | struct weston_touch *touch) |
| 462 | { |
| 463 | struct desktop_shell *shell = shsurf->shell; |
| 464 | |
| 465 | grab->grab.interface = interface; |
| 466 | grab->shsurf = shsurf; |
| 467 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 468 | wl_signal_add(&shsurf->destroy_signal, |
| 469 | &grab->shsurf_destroy_listener); |
| 470 | |
| 471 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 472 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 473 | |
| 474 | weston_touch_start_grab(touch, &grab->grab); |
| 475 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 476 | weston_touch_set_focus(touch->seat, |
| 477 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | static void |
| 481 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 482 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 483 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 484 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 485 | grab->shsurf->grabbed = 0; |
| 486 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 487 | |
| 488 | weston_touch_end_grab(grab->touch); |
| 489 | } |
| 490 | |
| 491 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 492 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 493 | struct weston_output *output); |
| 494 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 495 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 496 | get_modifier(char *modifier) |
| 497 | { |
| 498 | if (!modifier) |
| 499 | return MODIFIER_SUPER; |
| 500 | |
| 501 | if (!strcmp("ctrl", modifier)) |
| 502 | return MODIFIER_CTRL; |
| 503 | else if (!strcmp("alt", modifier)) |
| 504 | return MODIFIER_ALT; |
| 505 | else if (!strcmp("super", modifier)) |
| 506 | return MODIFIER_SUPER; |
| 507 | else |
| 508 | return MODIFIER_SUPER; |
| 509 | } |
| 510 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 511 | static enum animation_type |
| 512 | get_animation_type(char *animation) |
| 513 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 514 | if (!strcmp("zoom", animation)) |
| 515 | return ANIMATION_ZOOM; |
| 516 | else if (!strcmp("fade", animation)) |
| 517 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 518 | else if (!strcmp("dim-layer", animation)) |
| 519 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 520 | else |
| 521 | return ANIMATION_NONE; |
| 522 | } |
| 523 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 524 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 525 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 526 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 527 | struct weston_config_section *section; |
| 528 | int duration; |
| 529 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 530 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 531 | section = weston_config_get_section(shell->compositor->config, |
| 532 | "screensaver", NULL, NULL); |
| 533 | weston_config_section_get_string(section, |
| 534 | "path", &shell->screensaver.path, NULL); |
| 535 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 536 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 537 | |
| 538 | section = weston_config_get_section(shell->compositor->config, |
| 539 | "shell", NULL, NULL); |
| 540 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame^] | 541 | "client", &s, LIBEXECDIR "/weston-desktop-shell"); |
| 542 | shell->client = s; |
| 543 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 544 | "binding-modifier", &s, "super"); |
| 545 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 546 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 547 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 548 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 549 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 550 | weston_config_section_get_string(section, |
| 551 | "startup-animation", &s, "fade"); |
| 552 | shell->startup_animation_type = get_animation_type(s); |
| 553 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 554 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 555 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 556 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 557 | shell->focus_animation_type = get_animation_type(s); |
| 558 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 559 | weston_config_section_get_uint(section, "num-workspaces", |
| 560 | &shell->workspaces.num, |
| 561 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 562 | } |
| 563 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 564 | static struct weston_output * |
| 565 | get_default_output(struct weston_compositor *compositor) |
| 566 | { |
| 567 | return container_of(compositor->output_list.next, |
| 568 | struct weston_output, link); |
| 569 | } |
| 570 | |
| 571 | |
| 572 | /* no-op func for checking focus surface */ |
| 573 | static void |
| 574 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, |
| 575 | int32_t width, int32_t height) |
| 576 | { |
| 577 | } |
| 578 | |
| 579 | static struct focus_surface * |
| 580 | get_focus_surface(struct weston_surface *surface) |
| 581 | { |
| 582 | if (surface->configure == focus_surface_configure) |
| 583 | return surface->configure_private; |
| 584 | else |
| 585 | return NULL; |
| 586 | } |
| 587 | |
| 588 | static bool |
| 589 | is_focus_surface (struct weston_surface *es) |
| 590 | { |
| 591 | return (es->configure == focus_surface_configure); |
| 592 | } |
| 593 | |
| 594 | static bool |
| 595 | is_focus_view (struct weston_view *view) |
| 596 | { |
| 597 | return is_focus_surface (view->surface); |
| 598 | } |
| 599 | |
| 600 | static struct focus_surface * |
| 601 | create_focus_surface(struct weston_compositor *ec, |
| 602 | struct weston_output *output) |
| 603 | { |
| 604 | struct focus_surface *fsurf = NULL; |
| 605 | struct weston_surface *surface = NULL; |
| 606 | |
| 607 | fsurf = malloc(sizeof *fsurf); |
| 608 | if (!fsurf) |
| 609 | return NULL; |
| 610 | |
| 611 | fsurf->surface = weston_surface_create(ec); |
| 612 | surface = fsurf->surface; |
| 613 | if (surface == NULL) { |
| 614 | free(fsurf); |
| 615 | return NULL; |
| 616 | } |
| 617 | |
| 618 | surface->configure = focus_surface_configure; |
| 619 | surface->output = output; |
| 620 | surface->configure_private = fsurf; |
| 621 | |
| 622 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 623 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 624 | |
| 625 | weston_view_configure(fsurf->view, output->x, output->y, |
| 626 | output->width, output->height); |
| 627 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 628 | pixman_region32_fini(&surface->opaque); |
| 629 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 630 | output->width, output->height); |
| 631 | pixman_region32_fini(&surface->input); |
| 632 | pixman_region32_init(&surface->input); |
| 633 | |
| 634 | wl_list_init(&fsurf->workspace_transform.link); |
| 635 | |
| 636 | return fsurf; |
| 637 | } |
| 638 | |
| 639 | static void |
| 640 | focus_surface_destroy(struct focus_surface *fsurf) |
| 641 | { |
| 642 | weston_surface_destroy(fsurf->surface); |
| 643 | free(fsurf); |
| 644 | } |
| 645 | |
| 646 | static void |
| 647 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 648 | { |
| 649 | struct workspace *ws = data; |
| 650 | |
| 651 | ws->focus_animation = NULL; |
| 652 | } |
| 653 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 654 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 655 | focus_state_destroy(struct focus_state *state) |
| 656 | { |
| 657 | wl_list_remove(&state->seat_destroy_listener.link); |
| 658 | wl_list_remove(&state->surface_destroy_listener.link); |
| 659 | free(state); |
| 660 | } |
| 661 | |
| 662 | static void |
| 663 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 664 | { |
| 665 | struct focus_state *state = container_of(listener, |
| 666 | struct focus_state, |
| 667 | seat_destroy_listener); |
| 668 | |
| 669 | wl_list_remove(&state->link); |
| 670 | focus_state_destroy(state); |
| 671 | } |
| 672 | |
| 673 | static void |
| 674 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 675 | { |
| 676 | struct focus_state *state = container_of(listener, |
| 677 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 678 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 679 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 680 | struct weston_surface *main_surface, *next; |
| 681 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 682 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 683 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 684 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 685 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 686 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 687 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 688 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 689 | if (is_focus_view(view)) |
| 690 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 691 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 692 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 693 | break; |
| 694 | } |
| 695 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 696 | /* if the focus was a sub-surface, activate its main surface */ |
| 697 | if (main_surface != state->keyboard_focus) |
| 698 | next = main_surface; |
| 699 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 700 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 701 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 702 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 703 | activate(shell, next, state->seat); |
| 704 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 705 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 706 | if (state->ws->focus_animation) |
| 707 | weston_view_animation_destroy(state->ws->focus_animation); |
| 708 | |
| 709 | state->ws->focus_animation = weston_fade_run( |
| 710 | state->ws->fsurf_front->view, |
| 711 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 712 | focus_animation_done, state->ws); |
| 713 | } |
| 714 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 715 | wl_list_remove(&state->link); |
| 716 | focus_state_destroy(state); |
| 717 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 721 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 722 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 723 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 724 | |
| 725 | state = malloc(sizeof *state); |
| 726 | if (state == NULL) |
| 727 | return NULL; |
| 728 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 729 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 730 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 731 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 732 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 733 | |
| 734 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 735 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 736 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 737 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 738 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 739 | |
| 740 | return state; |
| 741 | } |
| 742 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 743 | static struct focus_state * |
| 744 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 745 | { |
| 746 | struct workspace *ws = get_current_workspace(shell); |
| 747 | struct focus_state *state; |
| 748 | |
| 749 | wl_list_for_each(state, &ws->focus_list, link) |
| 750 | if (state->seat == seat) |
| 751 | break; |
| 752 | |
| 753 | if (&state->link == &ws->focus_list) |
| 754 | state = focus_state_create(seat, ws); |
| 755 | |
| 756 | return state; |
| 757 | } |
| 758 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 759 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 760 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 761 | { |
| 762 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 763 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 764 | |
| 765 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 766 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 767 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 768 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
| 772 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 773 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 774 | struct weston_seat *seat) |
| 775 | { |
| 776 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 777 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 778 | |
| 779 | wl_list_for_each(state, &ws->focus_list, link) { |
| 780 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 781 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 782 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 783 | return; |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | static void |
| 789 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 790 | struct weston_surface *surface) |
| 791 | { |
| 792 | struct focus_state *state; |
| 793 | |
| 794 | wl_list_for_each(state, &ws->focus_list, link) |
| 795 | if (state->keyboard_focus == surface) |
| 796 | state->keyboard_focus = NULL; |
| 797 | } |
| 798 | |
| 799 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 800 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 801 | struct weston_view *from, struct weston_view *to) |
| 802 | { |
| 803 | struct weston_output *output; |
| 804 | bool focus_surface_created = false; |
| 805 | |
| 806 | /* FIXME: Only support dim animation using two layers */ |
| 807 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 808 | return; |
| 809 | |
| 810 | output = get_default_output(shell->compositor); |
| 811 | if (ws->fsurf_front == NULL && (from || to)) { |
| 812 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 813 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 814 | ws->fsurf_front->view->alpha = 0.0; |
| 815 | ws->fsurf_back->view->alpha = 0.0; |
| 816 | focus_surface_created = true; |
| 817 | } else { |
| 818 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 819 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 820 | } |
| 821 | |
| 822 | if (ws->focus_animation) { |
| 823 | weston_view_animation_destroy(ws->focus_animation); |
| 824 | ws->focus_animation = NULL; |
| 825 | } |
| 826 | |
| 827 | if (to) |
| 828 | wl_list_insert(&to->layer_link, |
| 829 | &ws->fsurf_front->view->layer_link); |
| 830 | else if (from) |
| 831 | wl_list_insert(&ws->layer.view_list, |
| 832 | &ws->fsurf_front->view->layer_link); |
| 833 | |
| 834 | if (focus_surface_created) { |
| 835 | ws->focus_animation = weston_fade_run( |
| 836 | ws->fsurf_front->view, |
| 837 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 838 | focus_animation_done, ws); |
| 839 | } else if (from) { |
| 840 | wl_list_insert(&from->layer_link, |
| 841 | &ws->fsurf_back->view->layer_link); |
| 842 | ws->focus_animation = weston_stable_fade_run( |
| 843 | ws->fsurf_front->view, 0.0, |
| 844 | ws->fsurf_back->view, 0.6, |
| 845 | focus_animation_done, ws); |
| 846 | } else if (to) { |
| 847 | wl_list_insert(&ws->layer.view_list, |
| 848 | &ws->fsurf_back->view->layer_link); |
| 849 | ws->focus_animation = weston_stable_fade_run( |
| 850 | ws->fsurf_front->view, 0.0, |
| 851 | ws->fsurf_back->view, 0.6, |
| 852 | focus_animation_done, ws); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 857 | workspace_destroy(struct workspace *ws) |
| 858 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 859 | struct focus_state *state, *next; |
| 860 | |
| 861 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 862 | focus_state_destroy(state); |
| 863 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 864 | if (ws->fsurf_front) |
| 865 | focus_surface_destroy(ws->fsurf_front); |
| 866 | if (ws->fsurf_back) |
| 867 | focus_surface_destroy(ws->fsurf_back); |
| 868 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 869 | free(ws); |
| 870 | } |
| 871 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 872 | static void |
| 873 | seat_destroyed(struct wl_listener *listener, void *data) |
| 874 | { |
| 875 | struct weston_seat *seat = data; |
| 876 | struct focus_state *state, *next; |
| 877 | struct workspace *ws = container_of(listener, |
| 878 | struct workspace, |
| 879 | seat_destroyed_listener); |
| 880 | |
| 881 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 882 | if (state->seat == seat) |
| 883 | wl_list_remove(&state->link); |
| 884 | } |
| 885 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 886 | static struct workspace * |
| 887 | workspace_create(void) |
| 888 | { |
| 889 | struct workspace *ws = malloc(sizeof *ws); |
| 890 | if (ws == NULL) |
| 891 | return NULL; |
| 892 | |
| 893 | weston_layer_init(&ws->layer, NULL); |
| 894 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 895 | wl_list_init(&ws->focus_list); |
| 896 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 897 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 898 | ws->fsurf_front = NULL; |
| 899 | ws->fsurf_back = NULL; |
| 900 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 901 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 902 | return ws; |
| 903 | } |
| 904 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 905 | static int |
| 906 | workspace_is_empty(struct workspace *ws) |
| 907 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 908 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 909 | } |
| 910 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 911 | static struct workspace * |
| 912 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 913 | { |
| 914 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 915 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 916 | pws += index; |
| 917 | return *pws; |
| 918 | } |
| 919 | |
| 920 | static struct workspace * |
| 921 | get_current_workspace(struct desktop_shell *shell) |
| 922 | { |
| 923 | return get_workspace(shell, shell->workspaces.current); |
| 924 | } |
| 925 | |
| 926 | static void |
| 927 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 928 | { |
| 929 | struct workspace *ws; |
| 930 | |
| 931 | ws = get_workspace(shell, index); |
| 932 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 933 | |
| 934 | shell->workspaces.current = index; |
| 935 | } |
| 936 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 937 | static unsigned int |
| 938 | get_output_height(struct weston_output *output) |
| 939 | { |
| 940 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 941 | } |
| 942 | |
| 943 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 944 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 945 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 946 | struct weston_transform *transform; |
| 947 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 948 | if (is_focus_view(view)) { |
| 949 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 950 | transform = &fsurf->workspace_transform; |
| 951 | } else { |
| 952 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 953 | transform = &shsurf->workspace_transform; |
| 954 | } |
| 955 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 956 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 957 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 958 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 959 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 960 | weston_matrix_init(&transform->matrix); |
| 961 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 962 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 963 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | static void |
| 967 | workspace_translate_out(struct workspace *ws, double fraction) |
| 968 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 969 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 970 | unsigned int height; |
| 971 | double d; |
| 972 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 973 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 974 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 975 | d = height * fraction; |
| 976 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 977 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | |
| 981 | static void |
| 982 | workspace_translate_in(struct workspace *ws, double fraction) |
| 983 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 984 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 985 | unsigned int height; |
| 986 | double d; |
| 987 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 988 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 989 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 990 | |
| 991 | if (fraction > 0) |
| 992 | d = -(height - height * fraction); |
| 993 | else |
| 994 | d = height + height * fraction; |
| 995 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 996 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | |
| 1000 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1001 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1002 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1003 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1004 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1005 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1006 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1007 | shell->workspaces.current, |
| 1008 | shell->workspaces.num); |
| 1009 | } |
| 1010 | |
| 1011 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1012 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1013 | unsigned int index, |
| 1014 | struct workspace *from, |
| 1015 | struct workspace *to) |
| 1016 | { |
| 1017 | shell->workspaces.current = index; |
| 1018 | |
| 1019 | shell->workspaces.anim_to = to; |
| 1020 | shell->workspaces.anim_from = from; |
| 1021 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1022 | shell->workspaces.anim_timestamp = 0; |
| 1023 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1024 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | static void |
| 1028 | workspace_deactivate_transforms(struct workspace *ws) |
| 1029 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1030 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1031 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1032 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1033 | 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] | 1034 | if (is_focus_view(view)) { |
| 1035 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1036 | transform = &fsurf->workspace_transform; |
| 1037 | } else { |
| 1038 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1039 | transform = &shsurf->workspace_transform; |
| 1040 | } |
| 1041 | |
| 1042 | if (!wl_list_empty(&transform->link)) { |
| 1043 | wl_list_remove(&transform->link); |
| 1044 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1045 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1046 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | static void |
| 1051 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1052 | struct workspace *from, |
| 1053 | struct workspace *to) |
| 1054 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1055 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1056 | |
| 1057 | wl_list_remove(&shell->workspaces.animation.link); |
| 1058 | workspace_deactivate_transforms(from); |
| 1059 | workspace_deactivate_transforms(to); |
| 1060 | shell->workspaces.anim_to = NULL; |
| 1061 | |
| 1062 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1063 | } |
| 1064 | |
| 1065 | static void |
| 1066 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1067 | struct weston_output *output, uint32_t msecs) |
| 1068 | { |
| 1069 | struct desktop_shell *shell = |
| 1070 | container_of(animation, struct desktop_shell, |
| 1071 | workspaces.animation); |
| 1072 | struct workspace *from = shell->workspaces.anim_from; |
| 1073 | struct workspace *to = shell->workspaces.anim_to; |
| 1074 | uint32_t t; |
| 1075 | double x, y; |
| 1076 | |
| 1077 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1078 | finish_workspace_change_animation(shell, from, to); |
| 1079 | return; |
| 1080 | } |
| 1081 | |
| 1082 | if (shell->workspaces.anim_timestamp == 0) { |
| 1083 | if (shell->workspaces.anim_current == 0.0) |
| 1084 | shell->workspaces.anim_timestamp = msecs; |
| 1085 | else |
| 1086 | shell->workspaces.anim_timestamp = |
| 1087 | msecs - |
| 1088 | /* Invers of movement function 'y' below. */ |
| 1089 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1090 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1091 | M_2_PI); |
| 1092 | } |
| 1093 | |
| 1094 | t = msecs - shell->workspaces.anim_timestamp; |
| 1095 | |
| 1096 | /* |
| 1097 | * x = [0, π/2] |
| 1098 | * y(x) = sin(x) |
| 1099 | */ |
| 1100 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1101 | y = sin(x); |
| 1102 | |
| 1103 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1104 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1105 | |
| 1106 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1107 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1108 | shell->workspaces.anim_current = y; |
| 1109 | |
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 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1112 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1113 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | static void |
| 1117 | animate_workspace_change(struct desktop_shell *shell, |
| 1118 | unsigned int index, |
| 1119 | struct workspace *from, |
| 1120 | struct workspace *to) |
| 1121 | { |
| 1122 | struct weston_output *output; |
| 1123 | |
| 1124 | int dir; |
| 1125 | |
| 1126 | if (index > shell->workspaces.current) |
| 1127 | dir = -1; |
| 1128 | else |
| 1129 | dir = 1; |
| 1130 | |
| 1131 | shell->workspaces.current = index; |
| 1132 | |
| 1133 | shell->workspaces.anim_dir = dir; |
| 1134 | shell->workspaces.anim_from = from; |
| 1135 | shell->workspaces.anim_to = to; |
| 1136 | shell->workspaces.anim_current = 0.0; |
| 1137 | shell->workspaces.anim_timestamp = 0; |
| 1138 | |
| 1139 | output = container_of(shell->compositor->output_list.next, |
| 1140 | struct weston_output, link); |
| 1141 | wl_list_insert(&output->animation_list, |
| 1142 | &shell->workspaces.animation.link); |
| 1143 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1144 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1145 | |
| 1146 | workspace_translate_in(to, 0); |
| 1147 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1148 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1149 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1150 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1153 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1154 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1155 | struct workspace *from, struct workspace *to) |
| 1156 | { |
| 1157 | shell->workspaces.current = index; |
| 1158 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1159 | wl_list_remove(&from->layer.link); |
| 1160 | } |
| 1161 | |
| 1162 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1163 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1164 | { |
| 1165 | struct workspace *from; |
| 1166 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1167 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1168 | |
| 1169 | if (index == shell->workspaces.current) |
| 1170 | return; |
| 1171 | |
| 1172 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1173 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1174 | return; |
| 1175 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1176 | from = get_current_workspace(shell); |
| 1177 | to = get_workspace(shell, index); |
| 1178 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1179 | if (shell->workspaces.anim_from == to && |
| 1180 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1181 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1183 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1184 | return; |
| 1185 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1186 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1187 | if (shell->workspaces.anim_to != NULL) |
| 1188 | finish_workspace_change_animation(shell, |
| 1189 | shell->workspaces.anim_from, |
| 1190 | shell->workspaces.anim_to); |
| 1191 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1192 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1193 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1194 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1195 | wl_list_for_each(state, &from->focus_list, link) |
| 1196 | if (state->keyboard_focus) |
| 1197 | animate_focus_change(shell, from, |
| 1198 | get_default_view(state->keyboard_focus), NULL); |
| 1199 | |
| 1200 | wl_list_for_each(state, &to->focus_list, link) |
| 1201 | if (state->keyboard_focus) |
| 1202 | animate_focus_change(shell, to, |
| 1203 | NULL, get_default_view(state->keyboard_focus)); |
| 1204 | } |
| 1205 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1206 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1207 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1208 | else |
| 1209 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1210 | |
| 1211 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1212 | } |
| 1213 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1214 | static bool |
| 1215 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1216 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1217 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1218 | struct wl_list *e; |
| 1219 | |
| 1220 | if (wl_list_empty(list)) |
| 1221 | return false; |
| 1222 | |
| 1223 | e = list->next; |
| 1224 | |
| 1225 | if (e->next != list) |
| 1226 | return false; |
| 1227 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1228 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1232 | move_view_to_workspace(struct desktop_shell *shell, |
| 1233 | struct weston_view *view, |
| 1234 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1235 | { |
| 1236 | struct workspace *from; |
| 1237 | struct workspace *to; |
| 1238 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1239 | struct weston_surface *focus; |
| 1240 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1241 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1242 | |
| 1243 | if (workspace == shell->workspaces.current) |
| 1244 | return; |
| 1245 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1246 | if (workspace >= shell->workspaces.num) |
| 1247 | workspace = shell->workspaces.num - 1; |
| 1248 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1249 | from = get_current_workspace(shell); |
| 1250 | to = get_workspace(shell, workspace); |
| 1251 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1252 | wl_list_remove(&view->layer_link); |
| 1253 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1254 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1255 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1256 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1257 | if (!seat->keyboard) |
| 1258 | continue; |
| 1259 | |
| 1260 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1261 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1262 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1263 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1264 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1265 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1269 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1270 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1271 | unsigned int index) |
| 1272 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1273 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1274 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1275 | struct shell_surface *shsurf; |
| 1276 | struct workspace *from; |
| 1277 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1278 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1279 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1280 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1281 | view = get_default_view(surface); |
| 1282 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1283 | index == shell->workspaces.current || |
| 1284 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1285 | return; |
| 1286 | |
| 1287 | from = get_current_workspace(shell); |
| 1288 | to = get_workspace(shell, index); |
| 1289 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1290 | wl_list_remove(&view->layer_link); |
| 1291 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1292 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1293 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1294 | drop_focus_state(shell, from, surface); |
| 1295 | |
| 1296 | if (shell->workspaces.anim_from == to && |
| 1297 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1298 | wl_list_remove(&to->layer.link); |
| 1299 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1300 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1301 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1302 | broadcast_current_workspace_state(shell); |
| 1303 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1304 | return; |
| 1305 | } |
| 1306 | |
| 1307 | if (shell->workspaces.anim_to != NULL) |
| 1308 | finish_workspace_change_animation(shell, |
| 1309 | shell->workspaces.anim_from, |
| 1310 | shell->workspaces.anim_to); |
| 1311 | |
| 1312 | if (workspace_is_empty(from) && |
| 1313 | workspace_has_only(to, surface)) |
| 1314 | update_workspace(shell, index, from, to); |
| 1315 | else { |
| 1316 | shsurf = get_shell_surface(surface); |
| 1317 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 1318 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1319 | &shsurf->workspace_transform.link); |
| 1320 | |
| 1321 | animate_workspace_change(shell, index, from, to); |
| 1322 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1323 | |
| 1324 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1325 | |
| 1326 | state = ensure_focus_state(shell, seat); |
| 1327 | if (state != NULL) |
| 1328 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | static void |
| 1332 | workspace_manager_move_surface(struct wl_client *client, |
| 1333 | struct wl_resource *resource, |
| 1334 | struct wl_resource *surface_resource, |
| 1335 | uint32_t workspace) |
| 1336 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1337 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1338 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1339 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1340 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1341 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1342 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1343 | main_surface = weston_surface_get_main_surface(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1344 | view = get_default_view(main_surface); |
| 1345 | if (!view) |
| 1346 | return; |
| 1347 | move_view_to_workspace(shell, view, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1351 | workspace_manager_move_surface, |
| 1352 | }; |
| 1353 | |
| 1354 | static void |
| 1355 | unbind_resource(struct wl_resource *resource) |
| 1356 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1357 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | static void |
| 1361 | bind_workspace_manager(struct wl_client *client, |
| 1362 | void *data, uint32_t version, uint32_t id) |
| 1363 | { |
| 1364 | struct desktop_shell *shell = data; |
| 1365 | struct wl_resource *resource; |
| 1366 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1367 | resource = wl_resource_create(client, |
| 1368 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1369 | |
| 1370 | if (resource == NULL) { |
| 1371 | weston_log("couldn't add workspace manager object"); |
| 1372 | return; |
| 1373 | } |
| 1374 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1375 | wl_resource_set_implementation(resource, |
| 1376 | &workspace_manager_implementation, |
| 1377 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1378 | wl_list_insert(&shell->workspaces.client_list, |
| 1379 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1380 | |
| 1381 | workspace_manager_send_state(resource, |
| 1382 | shell->workspaces.current, |
| 1383 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1384 | } |
| 1385 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1386 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1387 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1388 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1389 | { |
| 1390 | } |
| 1391 | |
| 1392 | static void |
| 1393 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1394 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1395 | struct weston_touch_move_grab *move = |
| 1396 | (struct weston_touch_move_grab *) container_of( |
| 1397 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1398 | |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1399 | if (grab->touch->seat->num_tp == 0) { |
| 1400 | shell_touch_grab_end(&move->base); |
| 1401 | free(move); |
| 1402 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | static void |
| 1406 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1407 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1408 | { |
| 1409 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1410 | struct shell_surface *shsurf = move->base.shsurf; |
| 1411 | struct weston_surface *es; |
| 1412 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1413 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1414 | |
| 1415 | if (!shsurf) |
| 1416 | return; |
| 1417 | |
| 1418 | es = shsurf->surface; |
| 1419 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1420 | weston_view_configure(shsurf->view, dx, dy, |
| 1421 | shsurf->view->geometry.width, |
| 1422 | shsurf->view->geometry.height); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1423 | |
| 1424 | weston_compositor_schedule_repaint(es->compositor); |
| 1425 | } |
| 1426 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1427 | static void |
| 1428 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1429 | { |
| 1430 | struct weston_touch_move_grab *move = |
| 1431 | (struct weston_touch_move_grab *) container_of( |
| 1432 | grab, struct shell_touch_grab, grab); |
| 1433 | |
| 1434 | shell_touch_grab_end(&move->base); |
| 1435 | free(move); |
| 1436 | } |
| 1437 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1438 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1439 | touch_move_grab_down, |
| 1440 | touch_move_grab_up, |
| 1441 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1442 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1443 | }; |
| 1444 | |
| 1445 | static int |
| 1446 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1447 | { |
| 1448 | struct weston_touch_move_grab *move; |
| 1449 | |
| 1450 | if (!shsurf) |
| 1451 | return -1; |
| 1452 | |
| 1453 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1454 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1455 | if (shsurf->grabbed) |
| 1456 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1457 | |
| 1458 | move = malloc(sizeof *move); |
| 1459 | if (!move) |
| 1460 | return -1; |
| 1461 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1462 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1463 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1464 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1465 | seat->touch->grab_y; |
| 1466 | |
| 1467 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1468 | seat->touch); |
| 1469 | |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1474 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1475 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1479 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1480 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1481 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1482 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1483 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1484 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1485 | int dx, dy; |
| 1486 | |
| 1487 | weston_pointer_move(pointer, x, y); |
| 1488 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1489 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1490 | |
| 1491 | if (!shsurf) |
| 1492 | return; |
| 1493 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1494 | weston_view_configure(shsurf->view, dx, dy, |
| 1495 | shsurf->view->geometry.width, |
| 1496 | shsurf->view->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1497 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1498 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1502 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1503 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1504 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1505 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1506 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1507 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1508 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1509 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1510 | if (pointer->button_count == 0 && |
| 1511 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1512 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1513 | free(grab); |
| 1514 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1515 | } |
| 1516 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1517 | static void |
| 1518 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1519 | { |
| 1520 | struct shell_grab *shell_grab = |
| 1521 | container_of(grab, struct shell_grab, grab); |
| 1522 | |
| 1523 | shell_grab_end(shell_grab); |
| 1524 | free(grab); |
| 1525 | } |
| 1526 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1527 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1528 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1529 | move_grab_motion, |
| 1530 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1531 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1532 | }; |
| 1533 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1534 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1535 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1536 | { |
| 1537 | struct weston_move_grab *move; |
| 1538 | |
| 1539 | if (!shsurf) |
| 1540 | return -1; |
| 1541 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1542 | if (shsurf->grabbed) |
| 1543 | return 0; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1544 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1545 | return 0; |
| 1546 | |
| 1547 | move = malloc(sizeof *move); |
| 1548 | if (!move) |
| 1549 | return -1; |
| 1550 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1551 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1552 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1553 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1554 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1555 | |
| 1556 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1557 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1558 | |
| 1559 | return 0; |
| 1560 | } |
| 1561 | |
| 1562 | static void |
| 1563 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1564 | struct wl_resource *seat_resource, uint32_t serial) |
| 1565 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1566 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1567 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1568 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1569 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1570 | if (seat->pointer && |
| 1571 | seat->pointer->button_count > 0 && |
| 1572 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1573 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1574 | if ((surface == shsurf->surface) && |
| 1575 | (surface_move(shsurf, seat) < 0)) |
| 1576 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1577 | } else if (seat->touch && |
| 1578 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1579 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1580 | if ((surface == shsurf->surface) && |
| 1581 | (surface_touch_move(shsurf, seat) < 0)) |
| 1582 | wl_resource_post_no_memory(resource); |
| 1583 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | struct weston_resize_grab { |
| 1587 | struct shell_grab base; |
| 1588 | uint32_t edges; |
| 1589 | int32_t width, height; |
| 1590 | }; |
| 1591 | |
| 1592 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1593 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1594 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1595 | { |
| 1596 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1597 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1598 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1599 | int32_t width, height; |
| 1600 | wl_fixed_t from_x, from_y; |
| 1601 | wl_fixed_t to_x, to_y; |
| 1602 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1603 | weston_pointer_move(pointer, x, y); |
| 1604 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1605 | if (!shsurf) |
| 1606 | return; |
| 1607 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1608 | weston_view_from_global_fixed(shsurf->view, |
| 1609 | pointer->grab_x, pointer->grab_y, |
| 1610 | &from_x, &from_y); |
| 1611 | weston_view_from_global_fixed(shsurf->view, |
| 1612 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1613 | |
| 1614 | width = resize->width; |
| 1615 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1616 | width += wl_fixed_to_int(from_x - to_x); |
| 1617 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1618 | width += wl_fixed_to_int(to_x - from_x); |
| 1619 | } |
| 1620 | |
| 1621 | height = resize->height; |
| 1622 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1623 | height += wl_fixed_to_int(from_y - to_y); |
| 1624 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1625 | height += wl_fixed_to_int(to_y - from_y); |
| 1626 | } |
| 1627 | |
| 1628 | shsurf->client->send_configure(shsurf->surface, |
| 1629 | resize->edges, width, height); |
| 1630 | } |
| 1631 | |
| 1632 | static void |
| 1633 | send_configure(struct weston_surface *surface, |
| 1634 | uint32_t edges, int32_t width, int32_t height) |
| 1635 | { |
| 1636 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1637 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1638 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1639 | edges, width, height); |
| 1640 | } |
| 1641 | |
| 1642 | static const struct weston_shell_client shell_client = { |
| 1643 | send_configure |
| 1644 | }; |
| 1645 | |
| 1646 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1647 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1648 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1649 | { |
| 1650 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1651 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1652 | enum wl_pointer_button_state state = state_w; |
| 1653 | |
| 1654 | if (pointer->button_count == 0 && |
| 1655 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1656 | shell_grab_end(&resize->base); |
| 1657 | free(grab); |
| 1658 | } |
| 1659 | } |
| 1660 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1661 | static void |
| 1662 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1663 | { |
| 1664 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1665 | |
| 1666 | shell_grab_end(&resize->base); |
| 1667 | free(grab); |
| 1668 | } |
| 1669 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1670 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1671 | noop_grab_focus, |
| 1672 | resize_grab_motion, |
| 1673 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1674 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1675 | }; |
| 1676 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1677 | /* |
| 1678 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1679 | * in the surface coordinates system. */ |
| 1680 | static void |
| 1681 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1682 | int32_t *y, int32_t *w, int32_t *h) { |
| 1683 | pixman_region32_t region; |
| 1684 | pixman_box32_t *box; |
| 1685 | struct weston_subsurface *subsurface; |
| 1686 | |
| 1687 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1688 | surface->width, |
| 1689 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1690 | |
| 1691 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1692 | pixman_region32_union_rect(®ion, ®ion, |
| 1693 | subsurface->position.x, |
| 1694 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1695 | subsurface->surface->width, |
| 1696 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | box = pixman_region32_extents(®ion); |
| 1700 | if (x) |
| 1701 | *x = box->x1; |
| 1702 | if (y) |
| 1703 | *y = box->y1; |
| 1704 | if (w) |
| 1705 | *w = box->x2 - box->x1; |
| 1706 | if (h) |
| 1707 | *h = box->y2 - box->y1; |
| 1708 | |
| 1709 | pixman_region32_fini(®ion); |
| 1710 | } |
| 1711 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1712 | static int |
| 1713 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1714 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1715 | { |
| 1716 | struct weston_resize_grab *resize; |
| 1717 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1718 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1719 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1720 | return 0; |
| 1721 | |
| 1722 | if (edges == 0 || edges > 15 || |
| 1723 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1724 | return 0; |
| 1725 | |
| 1726 | resize = malloc(sizeof *resize); |
| 1727 | if (!resize) |
| 1728 | return -1; |
| 1729 | |
| 1730 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1731 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1732 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1733 | |
| 1734 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1735 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1736 | |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
| 1740 | static void |
| 1741 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1742 | struct wl_resource *seat_resource, uint32_t serial, |
| 1743 | uint32_t edges) |
| 1744 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1745 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1746 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1747 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1748 | |
| 1749 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1750 | return; |
| 1751 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1752 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1753 | if (seat->pointer->button_count == 0 || |
| 1754 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1755 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1756 | return; |
| 1757 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1758 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1759 | wl_resource_post_no_memory(resource); |
| 1760 | } |
| 1761 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1762 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1763 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1764 | |
| 1765 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1766 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1767 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1768 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1769 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1770 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1771 | wl_fixed_t sx, sy; |
| 1772 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1773 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1774 | pointer->x, pointer->y, |
| 1775 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1776 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1777 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1778 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1782 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1783 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1784 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1785 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1786 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1787 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1788 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1789 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1790 | uint32_t time, uint32_t button, uint32_t state) |
| 1791 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1792 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1793 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1794 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1795 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1796 | if (shsurf && button == BTN_LEFT && state) { |
| 1797 | activate(shsurf->shell, shsurf->surface, seat); |
| 1798 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1799 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1800 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1801 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1802 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1803 | } |
| 1804 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1805 | static void |
| 1806 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1807 | { |
| 1808 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1809 | |
| 1810 | shell_grab_end(grab); |
| 1811 | free(grab); |
| 1812 | } |
| 1813 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1814 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1815 | busy_cursor_grab_focus, |
| 1816 | busy_cursor_grab_motion, |
| 1817 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1818 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1819 | }; |
| 1820 | |
| 1821 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1822 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1823 | { |
| 1824 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1825 | |
| 1826 | grab = malloc(sizeof *grab); |
| 1827 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1828 | return; |
| 1829 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1830 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1831 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1832 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1833 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1834 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1835 | end_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 = (struct shell_grab *) pointer->grab; |
| 1838 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1839 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1840 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1841 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1842 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1843 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1844 | } |
| 1845 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1846 | static void |
| 1847 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1848 | { |
| 1849 | if (!shsurf || !shsurf->ping_timer) |
| 1850 | return; |
| 1851 | |
| 1852 | if (shsurf->ping_timer->source) |
| 1853 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1854 | |
| 1855 | free(shsurf->ping_timer); |
| 1856 | shsurf->ping_timer = NULL; |
| 1857 | } |
| 1858 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1859 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1860 | ping_timeout_handler(void *data) |
| 1861 | { |
| 1862 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1863 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1864 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1865 | /* Client is not responding */ |
| 1866 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1867 | |
| 1868 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1869 | if (seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1870 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1871 | |
| 1872 | return 1; |
| 1873 | } |
| 1874 | |
| 1875 | static void |
| 1876 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1877 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1878 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1879 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1880 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1881 | |
| 1882 | if (!shsurf) |
| 1883 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1884 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1885 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1886 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1887 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1888 | return; |
| 1889 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1890 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1891 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1892 | if (!shsurf->ping_timer) |
| 1893 | return; |
| 1894 | |
| 1895 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1896 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1897 | shsurf->ping_timer->source = |
| 1898 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1899 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1900 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1901 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1906 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1907 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1908 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1909 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1910 | struct weston_compositor *compositor; |
| 1911 | struct shell_surface *shsurf; |
| 1912 | uint32_t serial; |
| 1913 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1914 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1915 | return; |
| 1916 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1917 | compositor = view->surface->compositor; |
| 1918 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1919 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1920 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1921 | set_busy_cursor(shsurf, pointer); |
| 1922 | } else { |
| 1923 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1924 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1929 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1930 | { |
| 1931 | struct wl_listener *listener; |
| 1932 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1933 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1934 | return; |
| 1935 | |
| 1936 | listener = malloc(sizeof *listener); |
| 1937 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1938 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1942 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1943 | uint32_t serial) |
| 1944 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1945 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1946 | struct weston_seat *seat; |
| 1947 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1948 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1949 | if (shsurf->ping_timer == NULL) |
| 1950 | /* Just ignore unsolicited pong. */ |
| 1951 | return; |
| 1952 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1953 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1954 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1955 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1956 | if(seat->pointer) |
| 1957 | end_busy_cursor(shsurf, seat->pointer); |
| 1958 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1959 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1963 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1964 | set_title(struct shell_surface *shsurf, const char *title) |
| 1965 | { |
| 1966 | free(shsurf->title); |
| 1967 | shsurf->title = strdup(title); |
| 1968 | } |
| 1969 | |
| 1970 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1971 | shell_surface_set_title(struct wl_client *client, |
| 1972 | struct wl_resource *resource, const char *title) |
| 1973 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1974 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1975 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1976 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | static void |
| 1980 | shell_surface_set_class(struct wl_client *client, |
| 1981 | struct wl_resource *resource, const char *class) |
| 1982 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1983 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1984 | |
| 1985 | free(shsurf->class); |
| 1986 | shsurf->class = strdup(class); |
| 1987 | } |
| 1988 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1989 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1990 | restore_output_mode(struct weston_output *output) |
| 1991 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1992 | if (output->current_mode != output->original_mode || |
| 1993 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1994 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1995 | output->original_mode, |
| 1996 | output->original_scale, |
| 1997 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | static void |
| 2001 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2002 | { |
| 2003 | struct weston_output *output; |
| 2004 | |
| 2005 | wl_list_for_each(output, &compositor->output_list, link) |
| 2006 | restore_output_mode(output); |
| 2007 | } |
| 2008 | |
| 2009 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2010 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 2011 | { |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2012 | struct workspace *ws; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2013 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2014 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2015 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2016 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2017 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2018 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2019 | shsurf->fullscreen.framerate = 0; |
| 2020 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2021 | wl_list_init(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2022 | if (shsurf->fullscreen.black_view) |
| 2023 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2024 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2025 | shsurf->fullscreen_output = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2026 | weston_view_set_position(shsurf->view, |
| 2027 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2028 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2029 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2030 | &shsurf->rotation.transform.link); |
| 2031 | shsurf->saved_rotation_valid = false; |
| 2032 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2033 | |
| 2034 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2035 | wl_list_remove(&shsurf->view->layer_link); |
| 2036 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2037 | } |
| 2038 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2039 | static void |
| 2040 | shell_unset_maximized(struct shell_surface *shsurf) |
| 2041 | { |
| 2042 | struct workspace *ws; |
| 2043 | /* undo all maximized things here */ |
| 2044 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2045 | weston_view_set_position(shsurf->view, |
| 2046 | shsurf->saved_x, |
| 2047 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2048 | |
| 2049 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2050 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2051 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2052 | shsurf->saved_rotation_valid = false; |
| 2053 | } |
| 2054 | |
| 2055 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2056 | wl_list_remove(&shsurf->view->layer_link); |
| 2057 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2058 | } |
| 2059 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2060 | static int |
| 2061 | reset_shell_surface_type(struct shell_surface *surface) |
| 2062 | { |
| 2063 | switch (surface->type) { |
| 2064 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2065 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2066 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2067 | case SHELL_SURFACE_MAXIMIZED: |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2068 | shell_unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2069 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2070 | case SHELL_SURFACE_NONE: |
| 2071 | case SHELL_SURFACE_TOPLEVEL: |
| 2072 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2073 | case SHELL_SURFACE_POPUP: |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2074 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2075 | break; |
| 2076 | } |
| 2077 | |
| 2078 | surface->type = SHELL_SURFACE_NONE; |
| 2079 | return 0; |
| 2080 | } |
| 2081 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2082 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2083 | set_surface_type(struct shell_surface *shsurf) |
| 2084 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2085 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2086 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2087 | |
| 2088 | reset_shell_surface_type(shsurf); |
| 2089 | |
| 2090 | shsurf->type = shsurf->next_type; |
| 2091 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 2092 | |
| 2093 | switch (shsurf->type) { |
| 2094 | case SHELL_SURFACE_TOPLEVEL: |
| 2095 | break; |
| 2096 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2097 | if (pev) |
| 2098 | weston_view_set_position(shsurf->view, |
| 2099 | pev->geometry.x + shsurf->transient.x, |
| 2100 | pev->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2101 | break; |
| 2102 | |
| 2103 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2104 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2105 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2106 | shsurf->saved_y = shsurf->view->geometry.y; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2107 | shsurf->saved_position_valid = true; |
| 2108 | |
| 2109 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2110 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2111 | wl_list_init(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2112 | weston_view_geometry_dirty(shsurf->view); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2113 | shsurf->saved_rotation_valid = true; |
| 2114 | } |
| 2115 | break; |
| 2116 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2117 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2118 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2119 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2120 | break; |
| 2121 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2122 | default: |
| 2123 | break; |
| 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2128 | set_toplevel(struct shell_surface *shsurf) |
| 2129 | { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2130 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2134 | shell_surface_set_toplevel(struct wl_client *client, |
| 2135 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2136 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2137 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2138 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2139 | set_toplevel(surface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | static void |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2143 | set_transient(struct shell_surface *shsurf, |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2144 | struct weston_surface *parent, int x, int y, uint32_t flags) |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2145 | { |
| 2146 | /* assign to parents output */ |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2147 | shsurf->parent = parent; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2148 | shsurf->transient.x = x; |
| 2149 | shsurf->transient.y = y; |
| 2150 | shsurf->transient.flags = flags; |
| 2151 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 2152 | } |
| 2153 | |
| 2154 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2155 | shell_surface_set_transient(struct wl_client *client, |
| 2156 | struct wl_resource *resource, |
| 2157 | struct wl_resource *parent_resource, |
| 2158 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2159 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2160 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2161 | struct weston_surface *parent = |
| 2162 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2163 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2164 | set_transient(shsurf, parent, x, y, flags); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2165 | } |
| 2166 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2167 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2168 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2169 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2170 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2174 | get_output_panel_height(struct desktop_shell *shell, |
| 2175 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2176 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2177 | struct weston_view *view; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2178 | int panel_height = 0; |
| 2179 | |
| 2180 | if (!output) |
| 2181 | return 0; |
| 2182 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2183 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2184 | if (view->surface->output == output) { |
| 2185 | panel_height = view->geometry.height; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2186 | break; |
| 2187 | } |
| 2188 | } |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2189 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2190 | return panel_height; |
| 2191 | } |
| 2192 | |
| 2193 | static void |
| 2194 | shell_surface_set_maximized(struct wl_client *client, |
| 2195 | struct wl_resource *resource, |
| 2196 | struct wl_resource *output_resource ) |
| 2197 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2198 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2199 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2200 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2201 | uint32_t edges = 0, panel_height = 0; |
| 2202 | |
| 2203 | /* get the default output, if the client set it as NULL |
| 2204 | check whether the ouput is available */ |
| 2205 | if (output_resource) |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2206 | shsurf->output = wl_resource_get_user_data(output_resource); |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 2207 | else if (es->output) |
| 2208 | shsurf->output = es->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2209 | else |
| 2210 | shsurf->output = get_default_output(es->compositor); |
| 2211 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2212 | shell = shell_surface_get_shell(shsurf); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 2213 | panel_height = get_output_panel_height(shell, shsurf->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2214 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2215 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2216 | shsurf->client->send_configure(shsurf->surface, edges, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2217 | shsurf->output->width, |
| 2218 | shsurf->output->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2219 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2220 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2221 | } |
| 2222 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2223 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2224 | 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] | 2225 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2226 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2227 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2228 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2229 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2230 | { |
| 2231 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2232 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2233 | |
| 2234 | surface = weston_surface_create(ec); |
| 2235 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2236 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2237 | return NULL; |
| 2238 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2239 | view = weston_view_create(surface); |
| 2240 | if (surface == NULL) { |
| 2241 | weston_log("no memory\n"); |
| 2242 | weston_surface_destroy(surface); |
| 2243 | return NULL; |
| 2244 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2245 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2246 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2247 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2248 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2249 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2250 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2251 | pixman_region32_fini(&surface->input); |
| 2252 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2253 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2254 | weston_view_configure(view, x, y, w, h); |
| 2255 | |
| 2256 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | /* Create black surface and append it to the associated fullscreen surface. |
| 2260 | * Handle size dismatch and positioning according to the method. */ |
| 2261 | static void |
| 2262 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2263 | { |
| 2264 | struct weston_output *output = shsurf->fullscreen_output; |
| 2265 | struct weston_surface *surface = shsurf->surface; |
| 2266 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2267 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2268 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2269 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2270 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2271 | restore_output_mode(output); |
| 2272 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2273 | if (!shsurf->fullscreen.black_view) |
| 2274 | shsurf->fullscreen.black_view = |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2275 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2276 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2277 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2278 | output->width, |
| 2279 | output->height); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2280 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2281 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2282 | wl_list_insert(&shsurf->view->layer_link, |
| 2283 | &shsurf->fullscreen.black_view->layer_link); |
| 2284 | shsurf->fullscreen.black_view->surface->output = output; |
| 2285 | shsurf->fullscreen.black_view->output = output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2286 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2287 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2288 | &surf_width, &surf_height); |
| 2289 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2290 | switch (shsurf->fullscreen.type) { |
| 2291 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2292 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2293 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2294 | break; |
| 2295 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2296 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2297 | if (output->width == surf_width && |
| 2298 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2299 | weston_view_set_position(shsurf->view, |
| 2300 | output->x - surf_x, |
| 2301 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2302 | break; |
| 2303 | } |
| 2304 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2305 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2306 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2307 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2308 | output_aspect = (float) output->width / |
| 2309 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2310 | /* XXX: Use surf_width and surf_height here? */ |
| 2311 | surface_aspect = (float) surface->width / |
| 2312 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2313 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2314 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2315 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2316 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2317 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2318 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2319 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2320 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2321 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2322 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2323 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2324 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2325 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2326 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2327 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2328 | break; |
| 2329 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2330 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2331 | struct weston_mode mode = {0, |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 2332 | surf_width * surface->buffer_scale, |
| 2333 | surf_height * surface->buffer_scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2334 | shsurf->fullscreen.framerate}; |
| 2335 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2336 | if (weston_output_switch_mode(output, &mode, surface->buffer_scale, |
| 2337 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2338 | weston_view_set_position(shsurf->view, |
| 2339 | output->x - surf_x, |
| 2340 | output->y - surf_y); |
| 2341 | weston_view_configure(shsurf->fullscreen.black_view, |
| 2342 | output->x - surf_x, |
| 2343 | output->y - surf_y, |
| 2344 | output->width, |
| 2345 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2346 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2347 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2348 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2349 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2350 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2351 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2352 | break; |
| 2353 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2354 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2355 | break; |
| 2356 | default: |
| 2357 | break; |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | /* make the fullscreen and black surface at the top */ |
| 2362 | static void |
| 2363 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 2364 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2365 | struct weston_output *output = shsurf->fullscreen_output; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2366 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2367 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2368 | wl_list_remove(&shsurf->view->layer_link); |
| 2369 | wl_list_insert(&shell->fullscreen_layer.view_list, |
| 2370 | &shsurf->view->layer_link); |
| 2371 | weston_surface_damage(shsurf->surface); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2372 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2373 | if (!shsurf->fullscreen.black_view) |
| 2374 | shsurf->fullscreen.black_view = |
| 2375 | create_black_surface(shsurf->surface->compositor, |
| 2376 | shsurf->surface, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2377 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2378 | output->width, |
| 2379 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2380 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2381 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2382 | wl_list_insert(&shsurf->view->layer_link, |
| 2383 | &shsurf->fullscreen.black_view->layer_link); |
| 2384 | weston_surface_damage(shsurf->fullscreen.black_view->surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | static void |
| 2388 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2389 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2390 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2391 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2392 | } |
| 2393 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2394 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2395 | set_fullscreen(struct shell_surface *shsurf, |
| 2396 | uint32_t method, |
| 2397 | uint32_t framerate, |
| 2398 | struct weston_output *output) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2399 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2400 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2401 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2402 | if (output) |
| 2403 | shsurf->output = output; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 2404 | else if (es->output) |
| 2405 | shsurf->output = es->output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2406 | else |
| 2407 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2408 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2409 | shsurf->fullscreen_output = shsurf->output; |
| 2410 | shsurf->fullscreen.type = method; |
| 2411 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2412 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2413 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2414 | shsurf->client->send_configure(shsurf->surface, 0, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2415 | shsurf->output->width, |
| 2416 | shsurf->output->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2417 | } |
| 2418 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2419 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2420 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2421 | struct wl_resource *resource, |
| 2422 | uint32_t method, |
| 2423 | uint32_t framerate, |
| 2424 | struct wl_resource *output_resource) |
| 2425 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2426 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2427 | struct weston_output *output; |
| 2428 | |
| 2429 | if (output_resource) |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2430 | output = wl_resource_get_user_data(output_resource); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2431 | else |
| 2432 | output = NULL; |
| 2433 | |
| 2434 | set_fullscreen(shsurf, method, framerate, output); |
| 2435 | } |
| 2436 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2437 | static void |
| 2438 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2439 | { |
| 2440 | /* XXX: using the same fields for transient type */ |
| 2441 | shsurf->transient.x = x; |
| 2442 | shsurf->transient.y = y; |
| 2443 | shsurf->transient.flags = flags; |
| 2444 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2445 | } |
| 2446 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2447 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2448 | |
| 2449 | static void |
| 2450 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2451 | { |
| 2452 | struct shell_seat *shseat = |
| 2453 | container_of(listener, |
| 2454 | struct shell_seat, seat_destroy_listener); |
| 2455 | struct shell_surface *shsurf, *prev = NULL; |
| 2456 | |
| 2457 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2458 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2459 | shseat->popup_grab.client = NULL; |
| 2460 | |
| 2461 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2462 | shsurf->popup.shseat = NULL; |
| 2463 | if (prev) { |
| 2464 | wl_list_init(&prev->popup.grab_link); |
| 2465 | } |
| 2466 | prev = shsurf; |
| 2467 | } |
| 2468 | wl_list_init(&prev->popup.grab_link); |
| 2469 | } |
| 2470 | |
| 2471 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2472 | free(shseat); |
| 2473 | } |
| 2474 | |
| 2475 | static struct shell_seat * |
| 2476 | create_shell_seat(struct weston_seat *seat) |
| 2477 | { |
| 2478 | struct shell_seat *shseat; |
| 2479 | |
| 2480 | shseat = calloc(1, sizeof *shseat); |
| 2481 | if (!shseat) { |
| 2482 | weston_log("no memory to allocate shell seat\n"); |
| 2483 | return NULL; |
| 2484 | } |
| 2485 | |
| 2486 | shseat->seat = seat; |
| 2487 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2488 | |
| 2489 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2490 | wl_signal_add(&seat->destroy_signal, |
| 2491 | &shseat->seat_destroy_listener); |
| 2492 | |
| 2493 | return shseat; |
| 2494 | } |
| 2495 | |
| 2496 | static struct shell_seat * |
| 2497 | get_shell_seat(struct weston_seat *seat) |
| 2498 | { |
| 2499 | struct wl_listener *listener; |
| 2500 | |
| 2501 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2502 | if (listener == NULL) |
| 2503 | return create_shell_seat(seat); |
| 2504 | |
| 2505 | return container_of(listener, |
| 2506 | struct shell_seat, seat_destroy_listener); |
| 2507 | } |
| 2508 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2509 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2510 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2511 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2512 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2513 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2514 | struct shell_seat *shseat = |
| 2515 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2516 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2517 | wl_fixed_t sx, sy; |
| 2518 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2519 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2520 | pointer->x, pointer->y, |
| 2521 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2522 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2523 | if (view && view->surface->resource && |
| 2524 | wl_resource_get_client(view->surface->resource) == client) { |
| 2525 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2526 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2527 | weston_pointer_set_focus(pointer, NULL, |
| 2528 | wl_fixed_from_int(0), |
| 2529 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2534 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2535 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2536 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2537 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2538 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2539 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2540 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2541 | weston_pointer_move(pointer, x, y); |
| 2542 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2543 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2544 | weston_view_from_global_fixed(pointer->focus, |
| 2545 | pointer->x, pointer->y, |
| 2546 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2547 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2548 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2552 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2553 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2554 | { |
| 2555 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2556 | struct shell_seat *shseat = |
| 2557 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2558 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2559 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2560 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2561 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2562 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2563 | resource_list = &grab->pointer->focus_resource_list; |
| 2564 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2565 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2566 | wl_resource_for_each(resource, resource_list) { |
| 2567 | wl_pointer_send_button(resource, serial, |
| 2568 | time, button, state); |
| 2569 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2570 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2571 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2572 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2573 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2574 | } |
| 2575 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2576 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2577 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2578 | } |
| 2579 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2580 | static void |
| 2581 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2582 | { |
| 2583 | popup_grab_end(grab->pointer); |
| 2584 | } |
| 2585 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2586 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2587 | popup_grab_focus, |
| 2588 | popup_grab_motion, |
| 2589 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2590 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2591 | }; |
| 2592 | |
| 2593 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2594 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2595 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2596 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2597 | struct shell_seat *shseat = |
| 2598 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2599 | struct shell_surface *shsurf; |
| 2600 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2601 | |
| 2602 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2603 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2604 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2605 | shseat->popup_grab.grab.interface = NULL; |
| 2606 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2607 | /* Send the popup_done event to all the popups open */ |
| 2608 | 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] | 2609 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2610 | shsurf->popup.shseat = NULL; |
| 2611 | if (prev) { |
| 2612 | wl_list_init(&prev->popup.grab_link); |
| 2613 | } |
| 2614 | prev = shsurf; |
| 2615 | } |
| 2616 | wl_list_init(&prev->popup.grab_link); |
| 2617 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | static void |
| 2622 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2623 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2624 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2625 | |
| 2626 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2627 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2628 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2629 | /* We must make sure here that this popup was opened after |
| 2630 | * a mouse press, and not just by moving around with other |
| 2631 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2632 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2633 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2634 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2635 | 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] | 2636 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2637 | } else { |
| 2638 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2639 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | static void |
| 2643 | remove_popup_grab(struct shell_surface *shsurf) |
| 2644 | { |
| 2645 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2646 | |
| 2647 | wl_list_remove(&shsurf->popup.grab_link); |
| 2648 | wl_list_init(&shsurf->popup.grab_link); |
| 2649 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2650 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2651 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2656 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2657 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2658 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2659 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2660 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2661 | shsurf->surface->output = parent_view->output; |
| 2662 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2663 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2664 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2665 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2666 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2667 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2668 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2669 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2670 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2671 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2672 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2673 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | static void |
| 2677 | shell_surface_set_popup(struct wl_client *client, |
| 2678 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2679 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2680 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2681 | struct wl_resource *parent_resource, |
| 2682 | int32_t x, int32_t y, uint32_t flags) |
| 2683 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2684 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2685 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2686 | shsurf->type = SHELL_SURFACE_POPUP; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2687 | shsurf->parent = wl_resource_get_user_data(parent_resource); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2688 | shsurf->popup.shseat = get_shell_seat(wl_resource_get_user_data(seat_resource)); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2689 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2690 | shsurf->popup.x = x; |
| 2691 | shsurf->popup.y = y; |
| 2692 | } |
| 2693 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2694 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2695 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2696 | shell_surface_move, |
| 2697 | shell_surface_resize, |
| 2698 | shell_surface_set_toplevel, |
| 2699 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2700 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2701 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2702 | shell_surface_set_maximized, |
| 2703 | shell_surface_set_title, |
| 2704 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2705 | }; |
| 2706 | |
| 2707 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2708 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2709 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2710 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2711 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2712 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2713 | remove_popup_grab(shsurf); |
| 2714 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2715 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2716 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2717 | shell_surface_is_top_fullscreen(shsurf)) |
| 2718 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2719 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2720 | if (shsurf->fullscreen.black_view) |
| 2721 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2722 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2723 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2724 | * we can always remove the listener. |
| 2725 | */ |
| 2726 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2727 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2728 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2729 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2730 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2731 | weston_view_destroy(shsurf->view); |
| 2732 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2733 | wl_list_remove(&shsurf->link); |
| 2734 | free(shsurf); |
| 2735 | } |
| 2736 | |
| 2737 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2738 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2739 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2740 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2741 | |
| 2742 | destroy_shell_surface(shsurf); |
| 2743 | } |
| 2744 | |
| 2745 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2746 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2747 | { |
| 2748 | struct shell_surface *shsurf = container_of(listener, |
| 2749 | struct shell_surface, |
| 2750 | surface_destroy_listener); |
| 2751 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2752 | if (shsurf->resource) |
| 2753 | wl_resource_destroy(shsurf->resource); |
| 2754 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2755 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2756 | } |
| 2757 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2758 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2759 | 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] | 2760 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2761 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2762 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2763 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2764 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2765 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2766 | else |
| 2767 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2768 | } |
| 2769 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2770 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2771 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2772 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2773 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2774 | struct shell_surface *shsurf; |
| 2775 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2776 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2777 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2778 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2779 | } |
| 2780 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2781 | shsurf = calloc(1, sizeof *shsurf); |
| 2782 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2783 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2784 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2785 | } |
| 2786 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2787 | shsurf->view = weston_view_create(surface); |
| 2788 | if (!shsurf->view) { |
| 2789 | weston_log("no memory to allocate shell surface\n"); |
| 2790 | free(shsurf); |
| 2791 | return NULL; |
| 2792 | } |
| 2793 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2794 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2795 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2796 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2797 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2798 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2799 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2800 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2801 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2802 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2803 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2804 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2805 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2806 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2807 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2808 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2809 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2810 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2811 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2812 | |
| 2813 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2814 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2815 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2816 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2817 | /* empty when not in use */ |
| 2818 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2819 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2820 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2821 | wl_list_init(&shsurf->workspace_transform.link); |
| 2822 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2823 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2824 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2825 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2826 | shsurf->client = client; |
| 2827 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2828 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2829 | } |
| 2830 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2831 | static struct weston_view * |
| 2832 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2833 | { |
| 2834 | return shsurf->view; |
| 2835 | } |
| 2836 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2837 | static void |
| 2838 | shell_get_shell_surface(struct wl_client *client, |
| 2839 | struct wl_resource *resource, |
| 2840 | uint32_t id, |
| 2841 | struct wl_resource *surface_resource) |
| 2842 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2843 | struct weston_surface *surface = |
| 2844 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2845 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2846 | struct shell_surface *shsurf; |
| 2847 | |
| 2848 | if (get_shell_surface(surface)) { |
| 2849 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2850 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2851 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2852 | return; |
| 2853 | } |
| 2854 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2855 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2856 | if (!shsurf) { |
| 2857 | wl_resource_post_error(surface_resource, |
| 2858 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2859 | "surface->configure already set"); |
| 2860 | return; |
| 2861 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2862 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2863 | shsurf->resource = |
| 2864 | wl_resource_create(client, |
| 2865 | &wl_shell_surface_interface, 1, id); |
| 2866 | wl_resource_set_implementation(shsurf->resource, |
| 2867 | &shell_surface_implementation, |
| 2868 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 2872 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2873 | }; |
| 2874 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2875 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 2876 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 2877 | |
| 2878 | static int |
| 2879 | screensaver_timeout(void *data) |
| 2880 | { |
| 2881 | struct desktop_shell *shell = data; |
| 2882 | |
| 2883 | shell_fade(shell, FADE_OUT); |
| 2884 | |
| 2885 | return 1; |
| 2886 | } |
| 2887 | |
| 2888 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2889 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2890 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2891 | struct desktop_shell *shell = |
| 2892 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2893 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2894 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2895 | |
| 2896 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 2897 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2898 | } |
| 2899 | |
| 2900 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2901 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2902 | { |
| 2903 | if (shell->screensaver.binding) |
| 2904 | return; |
| 2905 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2906 | if (!shell->screensaver.path) { |
| 2907 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2908 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2909 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2910 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2911 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2912 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2913 | return; |
| 2914 | } |
| 2915 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2916 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2917 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2918 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2919 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2920 | } |
| 2921 | |
| 2922 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2923 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2924 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2925 | if (shell->screensaver.process.pid == 0) |
| 2926 | return; |
| 2927 | |
| 2928 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2932 | 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] | 2933 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2934 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2935 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2936 | if (width == 0) |
| 2937 | return; |
| 2938 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2939 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 2940 | if (v->output == ev->output && v != ev) { |
| 2941 | weston_view_unmap(v); |
| 2942 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2943 | } |
| 2944 | } |
| 2945 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2946 | 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] | 2947 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2948 | if (wl_list_empty(&ev->layer_link)) { |
| 2949 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 2950 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2951 | } |
| 2952 | } |
| 2953 | |
| 2954 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2955 | 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] | 2956 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2957 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2958 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2959 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2960 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2961 | |
| 2962 | configure_static_view(view, &shell->background_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2966 | desktop_shell_set_background(struct wl_client *client, |
| 2967 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2968 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2969 | struct wl_resource *surface_resource) |
| 2970 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2971 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2972 | struct weston_surface *surface = |
| 2973 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2974 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2975 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2976 | if (surface->configure) { |
| 2977 | wl_resource_post_error(surface_resource, |
| 2978 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2979 | "surface role already assigned"); |
| 2980 | return; |
| 2981 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2982 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2983 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 2984 | weston_view_destroy(view); |
| 2985 | view = weston_view_create(surface); |
| 2986 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2987 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2988 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2989 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2990 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2991 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2992 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2993 | surface->output->width, |
| 2994 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2998 | 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] | 2999 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3000 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3001 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3002 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3003 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3004 | |
| 3005 | configure_static_view(view, &shell->panel_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3009 | desktop_shell_set_panel(struct wl_client *client, |
| 3010 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3011 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3012 | struct wl_resource *surface_resource) |
| 3013 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3014 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3015 | struct weston_surface *surface = |
| 3016 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3017 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3018 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3019 | if (surface->configure) { |
| 3020 | wl_resource_post_error(surface_resource, |
| 3021 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3022 | "surface role already assigned"); |
| 3023 | return; |
| 3024 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3025 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3026 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3027 | weston_view_destroy(view); |
| 3028 | view = weston_view_create(surface); |
| 3029 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3030 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3031 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3032 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3033 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3034 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3035 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3036 | surface->output->width, |
| 3037 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3038 | } |
| 3039 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3040 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3041 | 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] | 3042 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3043 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3044 | struct weston_view *view; |
| 3045 | |
| 3046 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3047 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3048 | if (width == 0) |
| 3049 | return; |
| 3050 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3051 | surface->width = width; |
| 3052 | surface->height = height; |
| 3053 | view->geometry.width = width; |
| 3054 | view->geometry.height = height; |
| 3055 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3056 | |
| 3057 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3058 | wl_list_insert(&shell->lock_layer.view_list, |
| 3059 | &view->layer_link); |
| 3060 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3061 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3066 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3067 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3068 | struct desktop_shell *shell = |
| 3069 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3070 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3071 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3072 | shell->lock_surface = NULL; |
| 3073 | } |
| 3074 | |
| 3075 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3076 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3077 | struct wl_resource *resource, |
| 3078 | struct wl_resource *surface_resource) |
| 3079 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3080 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3081 | struct weston_surface *surface = |
| 3082 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3083 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3084 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3085 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3086 | if (!shell->locked) |
| 3087 | return; |
| 3088 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3089 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3090 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3091 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3092 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3093 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3094 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3095 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3096 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3097 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3101 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3102 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3103 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3104 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3105 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3106 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3107 | wl_list_remove(&shell->lock_layer.link); |
| 3108 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3109 | &shell->fullscreen_layer.link); |
| 3110 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3111 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3112 | if (shell->showing_input_panels) { |
| 3113 | wl_list_insert(&shell->panel_layer.link, |
| 3114 | &shell->input_panel_layer.link); |
| 3115 | wl_list_insert(&shell->input_panel_layer.link, |
| 3116 | &ws->layer.link); |
| 3117 | } else { |
| 3118 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3119 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3120 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3121 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3122 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3123 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3124 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3125 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | static void |
| 3129 | desktop_shell_unlock(struct wl_client *client, |
| 3130 | struct wl_resource *resource) |
| 3131 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3132 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3133 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3134 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3135 | |
| 3136 | if (shell->locked) |
| 3137 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3138 | } |
| 3139 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3140 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3141 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3142 | struct wl_resource *resource, |
| 3143 | struct wl_resource *surface_resource) |
| 3144 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3145 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3146 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3147 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3148 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3149 | } |
| 3150 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3151 | static void |
| 3152 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3153 | struct wl_resource *resource) |
| 3154 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3155 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3156 | |
| 3157 | shell_fade_startup(shell); |
| 3158 | } |
| 3159 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3160 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3161 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3162 | desktop_shell_set_panel, |
| 3163 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3164 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3165 | desktop_shell_set_grab_surface, |
| 3166 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3167 | }; |
| 3168 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3169 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3170 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3171 | { |
| 3172 | struct shell_surface *shsurf; |
| 3173 | |
| 3174 | shsurf = get_shell_surface(surface); |
| 3175 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3176 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3177 | return shsurf->type; |
| 3178 | } |
| 3179 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3180 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3181 | 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] | 3182 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3183 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3184 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3185 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3186 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3187 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3188 | if (surface == NULL) |
| 3189 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3190 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3191 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3192 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3193 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3194 | return; |
| 3195 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3196 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3200 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3201 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3202 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3203 | struct weston_surface *surface; |
| 3204 | struct shell_surface *shsurf; |
| 3205 | |
| 3206 | surface = weston_surface_get_main_surface(focus); |
| 3207 | if (surface == NULL) |
| 3208 | return; |
| 3209 | |
| 3210 | shsurf = get_shell_surface(surface); |
| 3211 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3212 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
| 3213 | return; |
| 3214 | |
| 3215 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3216 | } |
| 3217 | |
| 3218 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3219 | 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] | 3220 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3221 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3222 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3223 | uint32_t edges = 0; |
| 3224 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3225 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3226 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3227 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3228 | if (surface == NULL) |
| 3229 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3230 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3231 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3232 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3233 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3234 | return; |
| 3235 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3236 | weston_view_from_global(shsurf->view, |
| 3237 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3238 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3239 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3240 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3241 | if (x < shsurf->view->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3242 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3243 | else if (x < 2 * shsurf->view->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3244 | edges |= 0; |
| 3245 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3246 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3247 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3248 | if (y < shsurf->view->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3249 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3250 | else if (y < 2 * shsurf->view->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3251 | edges |= 0; |
| 3252 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3253 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3254 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3255 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3259 | 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] | 3260 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3261 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3262 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3263 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3264 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3265 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3266 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3267 | /* XXX: broken for windows containing sub-surfaces */ |
| 3268 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3269 | if (surface == NULL) |
| 3270 | return; |
| 3271 | |
| 3272 | shsurf = get_shell_surface(surface); |
| 3273 | if (!shsurf) |
| 3274 | return; |
| 3275 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3276 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3277 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3278 | if (shsurf->view->alpha > 1.0) |
| 3279 | shsurf->view->alpha = 1.0; |
| 3280 | if (shsurf->view->alpha < step) |
| 3281 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3282 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3283 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3284 | weston_surface_damage(surface); |
| 3285 | } |
| 3286 | |
| 3287 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3288 | 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] | 3289 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3290 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3291 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3292 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3293 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3294 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3295 | |
| 3296 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3297 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3298 | wl_fixed_to_double(seat->pointer->x), |
| 3299 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3300 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3301 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3302 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3303 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3304 | increment = -output->zoom.increment; |
| 3305 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3306 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3307 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3308 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3309 | else |
| 3310 | increment = 0; |
| 3311 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3312 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3313 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3314 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3315 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3316 | else if (output->zoom.level > output->zoom.max_level) |
| 3317 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3318 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3319 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3320 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3321 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3322 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3323 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3324 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3325 | } |
| 3326 | } |
| 3327 | } |
| 3328 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3329 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3330 | 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] | 3331 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3332 | { |
| 3333 | do_zoom(seat, time, 0, axis, value); |
| 3334 | } |
| 3335 | |
| 3336 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3337 | 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] | 3338 | void *data) |
| 3339 | { |
| 3340 | do_zoom(seat, time, key, 0, 0); |
| 3341 | } |
| 3342 | |
| 3343 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3344 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3345 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3346 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3347 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3348 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3349 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3353 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 3354 | |
| 3355 | struct alt_tab { |
| 3356 | struct desktop_shell *shell; |
| 3357 | struct weston_keyboard_grab grab; |
| 3358 | |
| 3359 | struct wl_list *current; |
| 3360 | |
| 3361 | struct wl_list preview_list; |
| 3362 | }; |
| 3363 | |
| 3364 | struct alt_tab_preview { |
| 3365 | struct alt_tab *alt_tab; |
| 3366 | |
| 3367 | struct weston_view *view; |
| 3368 | struct weston_transform transform; |
| 3369 | |
| 3370 | struct wl_listener listener; |
| 3371 | |
| 3372 | struct wl_list link; |
| 3373 | }; |
| 3374 | |
| 3375 | static void |
| 3376 | alt_tab_next(struct alt_tab *alt_tab) |
| 3377 | { |
| 3378 | alt_tab->current = alt_tab->current->next; |
| 3379 | |
| 3380 | /* Make sure we're not pointing to the list header e.g. after |
| 3381 | * cycling through the whole list. */ |
| 3382 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3383 | alt_tab->current = alt_tab->current->next; |
| 3384 | } |
| 3385 | |
| 3386 | static void |
| 3387 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 3388 | { |
| 3389 | struct alt_tab_preview *preview, *next; |
| 3390 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 3391 | |
| 3392 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 3393 | preview = wl_container_of(alt_tab->current, preview, link); |
| 3394 | |
| 3395 | activate(alt_tab->shell, preview->view->surface, |
| 3396 | (struct weston_seat *) keyboard->seat); |
| 3397 | } |
| 3398 | |
| 3399 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 3400 | wl_list_remove(&preview->link); |
| 3401 | wl_list_remove(&preview->listener.link); |
| 3402 | weston_view_destroy(preview->view); |
| 3403 | free(preview); |
| 3404 | } |
| 3405 | |
| 3406 | weston_keyboard_end_grab(keyboard); |
| 3407 | if (keyboard->input_method_resource) |
| 3408 | keyboard->grab = &keyboard->input_method_grab; |
| 3409 | |
| 3410 | free(alt_tab); |
| 3411 | } |
| 3412 | |
| 3413 | static void |
| 3414 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3415 | { |
| 3416 | struct alt_tab_preview *preview = |
| 3417 | container_of(listener, struct alt_tab_preview, listener); |
| 3418 | struct alt_tab *alt_tab = preview->alt_tab; |
| 3419 | int advance = 0; |
| 3420 | |
| 3421 | /* If the preview that we're removing is the currently selected one, |
| 3422 | * we want to move to the next one. So we move to ->prev and then |
| 3423 | * call _next() after removing the preview. */ |
| 3424 | if (alt_tab->current == &preview->link) { |
| 3425 | alt_tab->current = alt_tab->current->prev; |
| 3426 | advance = 1; |
| 3427 | } |
| 3428 | |
| 3429 | wl_list_remove(&preview->listener.link); |
| 3430 | wl_list_remove(&preview->link); |
| 3431 | |
| 3432 | free(preview); |
| 3433 | |
| 3434 | if (advance) |
| 3435 | alt_tab_next(alt_tab); |
| 3436 | |
| 3437 | /* If the last preview goes away, stop the alt-tab */ |
| 3438 | if (wl_list_empty(alt_tab->current)) |
| 3439 | alt_tab_destroy(alt_tab); |
| 3440 | } |
| 3441 | |
| 3442 | static void |
| 3443 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 3444 | uint32_t time, uint32_t key, uint32_t state_w) |
| 3445 | { |
| 3446 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3447 | enum wl_keyboard_key_state state = state_w; |
| 3448 | |
| 3449 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 3450 | alt_tab_next(alt_tab); |
| 3451 | } |
| 3452 | |
| 3453 | static void |
| 3454 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 3455 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3456 | uint32_t mods_locked, uint32_t group) |
| 3457 | { |
| 3458 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3459 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 3460 | |
| 3461 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 3462 | alt_tab_destroy(alt_tab); |
| 3463 | } |
| 3464 | |
| 3465 | static void |
| 3466 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 3467 | { |
| 3468 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3469 | |
| 3470 | alt_tab_destroy(alt_tab); |
| 3471 | } |
| 3472 | |
| 3473 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 3474 | alt_tab_key, |
| 3475 | alt_tab_modifier, |
| 3476 | alt_tab_cancel, |
| 3477 | }; |
| 3478 | |
| 3479 | static int |
| 3480 | view_for_alt_tab(struct weston_view *view) |
| 3481 | { |
| 3482 | if (!get_shell_surface(view->surface)) |
| 3483 | return 0; |
| 3484 | |
| 3485 | if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT) |
| 3486 | return 0; |
| 3487 | |
| 3488 | if (view != get_default_view(view->surface)) |
| 3489 | return 0; |
| 3490 | |
| 3491 | return 1; |
| 3492 | } |
| 3493 | |
| 3494 | static void |
| 3495 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 3496 | void *data) |
| 3497 | { |
| 3498 | struct alt_tab *alt_tab; |
| 3499 | struct desktop_shell *shell = data; |
| 3500 | struct weston_output *output = get_default_output(shell->compositor); |
| 3501 | struct workspace *ws; |
| 3502 | struct weston_view *view; |
| 3503 | int num_surfaces = 0; |
| 3504 | int x, y, side, margin; |
| 3505 | |
| 3506 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3507 | |
| 3508 | if (view_for_alt_tab(view)) |
| 3509 | num_surfaces++; |
| 3510 | } |
| 3511 | |
| 3512 | if (!num_surfaces) |
| 3513 | return; |
| 3514 | |
| 3515 | alt_tab = malloc(sizeof *alt_tab); |
| 3516 | if (!alt_tab) |
| 3517 | return; |
| 3518 | |
| 3519 | alt_tab->shell = shell; |
| 3520 | wl_list_init(&alt_tab->preview_list); |
| 3521 | alt_tab->current = &alt_tab->preview_list; |
| 3522 | |
| 3523 | restore_all_output_modes(shell->compositor); |
| 3524 | lower_fullscreen_layer(alt_tab->shell); |
| 3525 | |
| 3526 | alt_tab->grab.interface = &alt_tab_grab; |
| 3527 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 3528 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 3529 | |
| 3530 | ws = get_current_workspace(shell); |
| 3531 | |
| 3532 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 3533 | * and/or add a black surrounding background à la gnome-shell */ |
| 3534 | |
| 3535 | /* Determine the size for each preview */ |
| 3536 | side = output->width / num_surfaces; |
| 3537 | if (side > 200) |
| 3538 | side = 200; |
| 3539 | margin = side / 4; |
| 3540 | side -= margin; |
| 3541 | |
| 3542 | x = margin; |
| 3543 | y = (output->height - side) / 2; |
| 3544 | |
| 3545 | /* Create a view for each surface */ |
| 3546 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3547 | struct alt_tab_preview *preview; |
| 3548 | struct weston_view *v; |
| 3549 | float scale; |
| 3550 | |
| 3551 | if (!view_for_alt_tab(view)) |
| 3552 | continue; |
| 3553 | |
| 3554 | preview = malloc(sizeof *preview); |
| 3555 | if (!preview) { |
| 3556 | alt_tab_destroy(alt_tab); |
| 3557 | return; |
| 3558 | } |
| 3559 | |
| 3560 | preview->alt_tab = alt_tab; |
| 3561 | |
| 3562 | preview->view = v = weston_view_create(view->surface); |
| 3563 | v->output = view->output; |
| 3564 | weston_view_restack(v, &ws->layer.view_list); |
| 3565 | weston_view_configure(v, x, y, view->geometry.width, view->geometry.height); |
| 3566 | |
| 3567 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 3568 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 3569 | |
| 3570 | if (view->geometry.width > view->geometry.height) |
| 3571 | scale = side / (float) view->geometry.width; |
| 3572 | else |
| 3573 | scale = side / (float) view->geometry.height; |
| 3574 | |
| 3575 | wl_list_insert(&v->geometry.transformation_list, |
| 3576 | &preview->transform.link); |
| 3577 | weston_matrix_init(&preview->transform.matrix); |
| 3578 | weston_matrix_scale(&preview->transform.matrix, |
| 3579 | scale, scale, 1.0f); |
| 3580 | |
| 3581 | weston_view_geometry_dirty(v); |
| 3582 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 3583 | |
| 3584 | /* Insert at the end of the list */ |
| 3585 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 3586 | |
| 3587 | x += side + margin; |
| 3588 | } |
| 3589 | |
| 3590 | /* Start at the second preview so a simple <alt>tab changes window. |
| 3591 | * We set `current' to the first preview and not the second because |
| 3592 | * we're going to receive a key press callback for the initial |
| 3593 | * <alt>tab which will make `current' point to the second element. */ |
| 3594 | alt_tab_next(alt_tab); |
| 3595 | } |
| 3596 | |
| 3597 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3598 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3599 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3600 | { |
| 3601 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3602 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3603 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3604 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3605 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3606 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3607 | weston_pointer_move(pointer, x, y); |
| 3608 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3609 | if (!shsurf) |
| 3610 | return; |
| 3611 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3612 | cx = 0.5f * shsurf->view->geometry.width; |
| 3613 | cy = 0.5f * shsurf->view->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3614 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3615 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3616 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3617 | r = sqrtf(dx * dx + dy * dy); |
| 3618 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3619 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3620 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3621 | |
| 3622 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3623 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3624 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3625 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3626 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3627 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3628 | |
| 3629 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3630 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3631 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3632 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3633 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3634 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3635 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3636 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3637 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3638 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3639 | wl_list_init(&shsurf->rotation.transform.link); |
| 3640 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3641 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3642 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3643 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3644 | /* We need to adjust the position of the surface |
| 3645 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3646 | cposx = shsurf->view->geometry.x + cx; |
| 3647 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3648 | dposx = rotate->center.x - cposx; |
| 3649 | dposy = rotate->center.y - cposy; |
| 3650 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3651 | weston_view_set_position(shsurf->view, |
| 3652 | shsurf->view->geometry.x + dposx, |
| 3653 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3654 | } |
| 3655 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3656 | /* Repaint implies weston_surface_update_transform(), which |
| 3657 | * lazily applies the damage due to rotation update. |
| 3658 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3659 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3660 | } |
| 3661 | |
| 3662 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3663 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3664 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3665 | { |
| 3666 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3667 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3668 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3669 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3670 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3671 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3672 | if (pointer->button_count == 0 && |
| 3673 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3674 | if (shsurf) |
| 3675 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3676 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3677 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3678 | free(rotate); |
| 3679 | } |
| 3680 | } |
| 3681 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3682 | static void |
| 3683 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3684 | { |
| 3685 | struct rotate_grab *rotate = |
| 3686 | container_of(grab, struct rotate_grab, base.grab); |
| 3687 | |
| 3688 | shell_grab_end(&rotate->base); |
| 3689 | free(rotate); |
| 3690 | } |
| 3691 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3692 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3693 | noop_grab_focus, |
| 3694 | rotate_grab_motion, |
| 3695 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3696 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3697 | }; |
| 3698 | |
| 3699 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3700 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3701 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3702 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3703 | float dx, dy; |
| 3704 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3705 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3706 | rotate = malloc(sizeof *rotate); |
| 3707 | if (!rotate) |
| 3708 | return; |
| 3709 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3710 | weston_view_to_global_float(surface->view, |
| 3711 | surface->view->geometry.width * 0.5f, |
| 3712 | surface->view->geometry.height * 0.5f, |
| 3713 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3714 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3715 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3716 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3717 | r = sqrtf(dx * dx + dy * dy); |
| 3718 | if (r > 20.0f) { |
| 3719 | struct weston_matrix inverse; |
| 3720 | |
| 3721 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3722 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3723 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3724 | |
| 3725 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3726 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3727 | } else { |
| 3728 | weston_matrix_init(&surface->rotation.rotation); |
| 3729 | weston_matrix_init(&rotate->rotation); |
| 3730 | } |
| 3731 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3732 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3733 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3737 | 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] | 3738 | void *data) |
| 3739 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3740 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3741 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3742 | struct shell_surface *surface; |
| 3743 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3744 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3745 | if (base_surface == NULL) |
| 3746 | return; |
| 3747 | |
| 3748 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3749 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 3750 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3751 | return; |
| 3752 | |
| 3753 | surface_rotate(surface, seat); |
| 3754 | } |
| 3755 | |
| 3756 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3757 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 3758 | { |
| 3759 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3760 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3761 | |
| 3762 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3763 | wl_list_for_each_reverse_safe(view, prev, |
| 3764 | &shell->fullscreen_layer.view_list, |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3765 | layer_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3766 | weston_view_restack(view, &ws->layer.view_list); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3770 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3771 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3772 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3773 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3774 | struct weston_view *main_view; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3775 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3776 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3777 | struct weston_surface *old_es; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3778 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3779 | main_surface = weston_surface_get_main_surface(es); |
| 3780 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3781 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3782 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3783 | state = ensure_focus_state(shell, seat); |
| 3784 | if (state == NULL) |
| 3785 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3786 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3787 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3788 | state->keyboard_focus = es; |
| 3789 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3790 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3791 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3792 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3793 | case SHELL_SURFACE_FULLSCREEN: |
| 3794 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3795 | shell_stack_fullscreen(get_shell_surface(main_surface)); |
| 3796 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3797 | return; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3798 | default: |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3799 | restore_all_output_modes(shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3800 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3801 | main_view = get_default_view(main_surface); |
| 3802 | if (main_view) |
| 3803 | weston_view_restack(main_view, &ws->layer.view_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3804 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3805 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3806 | |
| 3807 | if (shell->focus_animation_type != ANIMATION_NONE) |
| 3808 | 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] | 3809 | } |
| 3810 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3811 | /* no-op func for checking black surface */ |
| 3812 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3813 | 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] | 3814 | { |
| 3815 | } |
| 3816 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3817 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3818 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 3819 | { |
| 3820 | if (es->configure == black_surface_configure) { |
| 3821 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3822 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3823 | return true; |
| 3824 | } |
| 3825 | return false; |
| 3826 | } |
| 3827 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3828 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3829 | activate_binding(struct weston_seat *seat, |
| 3830 | struct desktop_shell *shell, |
| 3831 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3832 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3833 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3834 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3835 | if (!focus) |
| 3836 | return; |
| 3837 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3838 | if (is_black_surface(focus, &main_surface)) |
| 3839 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3840 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3841 | main_surface = weston_surface_get_main_surface(focus); |
| 3842 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3843 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3844 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3845 | activate(shell, focus, seat); |
| 3846 | } |
| 3847 | |
| 3848 | static void |
| 3849 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 3850 | void *data) |
| 3851 | { |
| 3852 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 3853 | return; |
| 3854 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3855 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | static void |
| 3859 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3860 | { |
| 3861 | if (seat->touch->grab != &seat->touch->default_grab) |
| 3862 | return; |
| 3863 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3864 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3868 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3869 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3870 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3871 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3872 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3873 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3874 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3875 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3876 | |
| 3877 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3878 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3879 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3880 | * toplevel layers. This way nothing else can show or receive |
| 3881 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3882 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3883 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3884 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3885 | if (shell->showing_input_panels) |
| 3886 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3887 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3888 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3889 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3890 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3891 | launch_screensaver(shell); |
| 3892 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3893 | /* TODO: disable bindings that should not work while locked. */ |
| 3894 | |
| 3895 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3896 | } |
| 3897 | |
| 3898 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3899 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3900 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3901 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3902 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3903 | return; |
| 3904 | } |
| 3905 | |
| 3906 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3907 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3908 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3909 | return; |
| 3910 | } |
| 3911 | |
| 3912 | if (shell->prepare_event_sent) |
| 3913 | return; |
| 3914 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3915 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3916 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3920 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3921 | { |
| 3922 | struct desktop_shell *shell = data; |
| 3923 | |
| 3924 | shell->fade.animation = NULL; |
| 3925 | |
| 3926 | switch (shell->fade.type) { |
| 3927 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3928 | weston_surface_destroy(shell->fade.view->surface); |
| 3929 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3930 | break; |
| 3931 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3932 | lock(shell); |
| 3933 | break; |
| 3934 | } |
| 3935 | } |
| 3936 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3937 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3938 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3939 | { |
| 3940 | struct weston_compositor *compositor = shell->compositor; |
| 3941 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3942 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3943 | |
| 3944 | surface = weston_surface_create(compositor); |
| 3945 | if (!surface) |
| 3946 | return NULL; |
| 3947 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3948 | view = weston_view_create(surface); |
| 3949 | if (!view) { |
| 3950 | weston_surface_destroy(surface); |
| 3951 | return NULL; |
| 3952 | } |
| 3953 | |
| 3954 | weston_view_configure(view, 0, 0, 8192, 8192); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3955 | 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] | 3956 | wl_list_insert(&compositor->fade_layer.view_list, |
| 3957 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3958 | pixman_region32_init(&surface->input); |
| 3959 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3960 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | static void |
| 3964 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 3965 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3966 | float tint; |
| 3967 | |
| 3968 | switch (type) { |
| 3969 | case FADE_IN: |
| 3970 | tint = 0.0; |
| 3971 | break; |
| 3972 | case FADE_OUT: |
| 3973 | tint = 1.0; |
| 3974 | break; |
| 3975 | default: |
| 3976 | weston_log("shell: invalid fade type\n"); |
| 3977 | return; |
| 3978 | } |
| 3979 | |
| 3980 | shell->fade.type = type; |
| 3981 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3982 | if (shell->fade.view == NULL) { |
| 3983 | shell->fade.view = shell_fade_create_surface(shell); |
| 3984 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3985 | return; |
| 3986 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3987 | shell->fade.view->alpha = 1.0 - tint; |
| 3988 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3989 | } |
| 3990 | |
| 3991 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 3992 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3993 | else |
| 3994 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3995 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 3996 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3997 | shell_fade_done, shell); |
| 3998 | } |
| 3999 | |
| 4000 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4001 | do_shell_fade_startup(void *data) |
| 4002 | { |
| 4003 | struct desktop_shell *shell = data; |
| 4004 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4005 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4006 | shell_fade(shell, FADE_IN); |
| 4007 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4008 | weston_surface_destroy(shell->fade.view->surface); |
| 4009 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4010 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4011 | } |
| 4012 | |
| 4013 | static void |
| 4014 | shell_fade_startup(struct desktop_shell *shell) |
| 4015 | { |
| 4016 | struct wl_event_loop *loop; |
| 4017 | |
| 4018 | if (!shell->fade.startup_timer) |
| 4019 | return; |
| 4020 | |
| 4021 | wl_event_source_remove(shell->fade.startup_timer); |
| 4022 | shell->fade.startup_timer = NULL; |
| 4023 | |
| 4024 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4025 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4026 | } |
| 4027 | |
| 4028 | static int |
| 4029 | fade_startup_timeout(void *data) |
| 4030 | { |
| 4031 | struct desktop_shell *shell = data; |
| 4032 | |
| 4033 | shell_fade_startup(shell); |
| 4034 | return 0; |
| 4035 | } |
| 4036 | |
| 4037 | static void |
| 4038 | shell_fade_init(struct desktop_shell *shell) |
| 4039 | { |
| 4040 | /* Make compositor output all black, and wait for the desktop-shell |
| 4041 | * client to signal it is ready, then fade in. The timer triggers a |
| 4042 | * fade-in, in case the desktop-shell client takes too long. |
| 4043 | */ |
| 4044 | |
| 4045 | struct wl_event_loop *loop; |
| 4046 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4047 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4048 | weston_log("%s: warning: fade surface already exists\n", |
| 4049 | __func__); |
| 4050 | return; |
| 4051 | } |
| 4052 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4053 | shell->fade.view = shell_fade_create_surface(shell); |
| 4054 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4055 | return; |
| 4056 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4057 | weston_view_update_transform(shell->fade.view); |
| 4058 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4059 | |
| 4060 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4061 | shell->fade.startup_timer = |
| 4062 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4063 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4064 | } |
| 4065 | |
| 4066 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4067 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4068 | { |
| 4069 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4070 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4071 | |
| 4072 | shell_fade(shell, FADE_OUT); |
| 4073 | /* lock() is called from shell_fade_done() */ |
| 4074 | } |
| 4075 | |
| 4076 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4077 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4078 | { |
| 4079 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4080 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4081 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4082 | unlock(shell); |
| 4083 | } |
| 4084 | |
| 4085 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4086 | show_input_panels(struct wl_listener *listener, void *data) |
| 4087 | { |
| 4088 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4089 | container_of(listener, struct desktop_shell, |
| 4090 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4091 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4092 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4093 | shell->text_input.surface = (struct weston_surface*)data; |
| 4094 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4095 | if (shell->showing_input_panels) |
| 4096 | return; |
| 4097 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4098 | shell->showing_input_panels = true; |
| 4099 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4100 | if (!shell->locked) |
| 4101 | wl_list_insert(&shell->panel_layer.link, |
| 4102 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4103 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4104 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4105 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4106 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4107 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4108 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4109 | &ipsurf->view->layer_link); |
| 4110 | weston_view_geometry_dirty(ipsurf->view); |
| 4111 | weston_view_update_transform(ipsurf->view); |
| 4112 | weston_surface_damage(ipsurf->surface); |
| 4113 | weston_slide_run(ipsurf->view, ipsurf->view->geometry.height, |
| 4114 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | static void |
| 4119 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4120 | { |
| 4121 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4122 | container_of(listener, struct desktop_shell, |
| 4123 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4124 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4125 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4126 | if (!shell->showing_input_panels) |
| 4127 | return; |
| 4128 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4129 | shell->showing_input_panels = false; |
| 4130 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4131 | if (!shell->locked) |
| 4132 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4133 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4134 | wl_list_for_each_safe(view, next, |
| 4135 | &shell->input_panel_layer.view_list, layer_link) |
| 4136 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4140 | update_input_panels(struct wl_listener *listener, void *data) |
| 4141 | { |
| 4142 | struct desktop_shell *shell = |
| 4143 | container_of(listener, struct desktop_shell, |
| 4144 | update_input_panel_listener); |
| 4145 | |
| 4146 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4147 | } |
| 4148 | |
| 4149 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4150 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4151 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4152 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4153 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4154 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4155 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4156 | |
| 4157 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4158 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4159 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4160 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4164 | weston_view_set_initial_position(struct weston_view *view, |
| 4165 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4166 | { |
| 4167 | struct weston_compositor *compositor = shell->compositor; |
| 4168 | int ix = 0, iy = 0; |
| 4169 | int range_x, range_y; |
| 4170 | int dx, dy, x, y, panel_height; |
| 4171 | struct weston_output *output, *target_output = NULL; |
| 4172 | struct weston_seat *seat; |
| 4173 | |
| 4174 | /* As a heuristic place the new window on the same output as the |
| 4175 | * pointer. Falling back to the output containing 0, 0. |
| 4176 | * |
| 4177 | * TODO: Do something clever for touch too? |
| 4178 | */ |
| 4179 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4180 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4181 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4182 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4183 | break; |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4188 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4189 | target_output = output; |
| 4190 | break; |
| 4191 | } |
| 4192 | } |
| 4193 | |
| 4194 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4195 | weston_view_set_position(view, 10 + random() % 400, |
| 4196 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4197 | return; |
| 4198 | } |
| 4199 | |
| 4200 | /* Valid range within output where the surface will still be onscreen. |
| 4201 | * If this is negative it means that the surface is bigger than |
| 4202 | * output. |
| 4203 | */ |
| 4204 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4205 | range_x = target_output->width - view->geometry.width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4206 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4207 | view->geometry.height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4208 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4209 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4210 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4211 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4212 | dx = 0; |
| 4213 | |
| 4214 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4215 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4216 | else |
| 4217 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4218 | |
| 4219 | x = target_output->x + dx; |
| 4220 | y = target_output->y + dy; |
| 4221 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4222 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4226 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4227 | 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] | 4228 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4229 | struct weston_compositor *compositor = shell->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4230 | struct weston_view *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4231 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4232 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4233 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4234 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4235 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4236 | shsurf->view->geometry.width = width; |
| 4237 | shsurf->view->geometry.height = height; |
| 4238 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4239 | |
| 4240 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4241 | switch (shsurf->type) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4242 | case SHELL_SURFACE_TOPLEVEL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4243 | weston_view_set_initial_position(shsurf->view, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4244 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4245 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4246 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4247 | shell_map_fullscreen(shsurf); |
| 4248 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4249 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4250 | /* use surface configure to set the geometry */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4251 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4252 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4253 | &surf_x, &surf_y, NULL, NULL); |
| 4254 | weston_view_set_position(shsurf->view, |
| 4255 | shsurf->output->x - surf_x, |
| 4256 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4257 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4258 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4259 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4260 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4261 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4262 | weston_view_set_position(shsurf->view, |
| 4263 | shsurf->view->geometry.x + sx, |
| 4264 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4265 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4266 | default: |
| 4267 | ; |
| 4268 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4269 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 4270 | /* surface stacking order, see also activate() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4271 | switch (shsurf->type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4272 | case SHELL_SURFACE_POPUP: |
| 4273 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4274 | /* TODO: Handle a parent with multiple views */ |
| 4275 | parent = get_default_view(shsurf->parent); |
| 4276 | if (parent) { |
| 4277 | wl_list_remove(&shsurf->view->layer_link); |
| 4278 | wl_list_insert(parent->layer_link.prev, |
| 4279 | &shsurf->view->layer_link); |
| 4280 | } |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4281 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4282 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 4283 | case SHELL_SURFACE_NONE: |
| 4284 | break; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4285 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4286 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4287 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4288 | wl_list_remove(&shsurf->view->layer_link); |
| 4289 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4290 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4291 | } |
| 4292 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4293 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4294 | weston_view_update_transform(shsurf->view); |
| 4295 | if (shsurf->type == SHELL_SURFACE_MAXIMIZED) { |
| 4296 | shsurf->surface->output = shsurf->output; |
| 4297 | shsurf->view->output = shsurf->output; |
| 4298 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4299 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4300 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4301 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4302 | /* XXX: xwayland's using the same fields for transient type */ |
| 4303 | case SHELL_SURFACE_XWAYLAND: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4304 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4305 | if (shsurf->transient.flags == |
| 4306 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4307 | break; |
| 4308 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4309 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4310 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4311 | if (!shell->locked) { |
| 4312 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4313 | activate(shell, shsurf->surface, seat); |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4314 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4315 | break; |
| 4316 | default: |
| 4317 | break; |
| 4318 | } |
| 4319 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4320 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4321 | { |
| 4322 | switch (shell->win_animation_type) { |
| 4323 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4324 | 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] | 4325 | break; |
| 4326 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4327 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4328 | break; |
| 4329 | default: |
| 4330 | break; |
| 4331 | } |
| 4332 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4336 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4337 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4338 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4339 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 4340 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4341 | struct weston_view *view; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4342 | int32_t surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4343 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4344 | shsurf = get_shell_surface(surface); |
| 4345 | if (shsurf) |
| 4346 | surface_type = shsurf->type; |
| 4347 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4348 | /* TODO: |
| 4349 | * This should probably be changed to be more shell_surface |
| 4350 | * dependent |
| 4351 | */ |
| 4352 | wl_list_for_each(view, &surface->views, surface_link) |
| 4353 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4354 | |
| 4355 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4356 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 4357 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4358 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4359 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4360 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4361 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4362 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4363 | NULL, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4364 | shsurf->view->geometry.x = shsurf->output->x - surf_x; |
| 4365 | shsurf->view->geometry.y = shsurf->output->y + |
| 4366 | get_output_panel_height(shell,shsurf->output) - surf_y; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4367 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4368 | case SHELL_SURFACE_TOPLEVEL: |
| 4369 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4370 | default: |
| 4371 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4372 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4373 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4374 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4375 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4376 | wl_list_for_each(view, &surface->views, surface_link) |
| 4377 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4378 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4379 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4380 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4381 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4382 | } |
| 4383 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4384 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4385 | 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] | 4386 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4387 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4388 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4389 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4390 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4391 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4392 | if (!weston_surface_is_mapped(es) && |
| 4393 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4394 | remove_popup_grab(shsurf); |
| 4395 | } |
| 4396 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4397 | if (width == 0) |
| 4398 | return; |
| 4399 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4400 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4401 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4402 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4403 | type_changed = 1; |
| 4404 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4405 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4406 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4407 | map(shell, shsurf, width, height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4408 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4409 | shsurf->view->geometry.width != width || |
| 4410 | shsurf->view->geometry.height != height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4411 | float from_x, from_y; |
| 4412 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4413 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4414 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4415 | 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] | 4416 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4417 | shsurf->view->geometry.x + to_x - from_x, |
| 4418 | shsurf->view->geometry.y + to_y - from_y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4419 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4420 | } |
| 4421 | } |
| 4422 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4423 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4424 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4425 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4426 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4427 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4428 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4429 | struct desktop_shell *shell = |
| 4430 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4431 | |
| 4432 | shell->child.process.pid = 0; |
| 4433 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4434 | |
| 4435 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4436 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4437 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4438 | shell->child.deathstamp = time; |
| 4439 | shell->child.deathcount = 0; |
| 4440 | } |
| 4441 | |
| 4442 | shell->child.deathcount++; |
| 4443 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame^] | 4444 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4445 | return; |
| 4446 | } |
| 4447 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame^] | 4448 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4449 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4450 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4451 | } |
| 4452 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4453 | static void |
| 4454 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4455 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4456 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4457 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4458 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4459 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame^] | 4460 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4461 | desktop_shell_sigchld); |
| 4462 | |
| 4463 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame^] | 4464 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4468 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4469 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4470 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4471 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4472 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4473 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4474 | if (resource) |
| 4475 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4476 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4477 | } |
| 4478 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4479 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4480 | unbind_desktop_shell(struct wl_resource *resource) |
| 4481 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4482 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4483 | |
| 4484 | if (shell->locked) |
| 4485 | resume_desktop(shell); |
| 4486 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4487 | shell->child.desktop_shell = NULL; |
| 4488 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4492 | bind_desktop_shell(struct wl_client *client, |
| 4493 | void *data, uint32_t version, uint32_t id) |
| 4494 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4495 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4496 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4497 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4498 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4499 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4500 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4501 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4502 | wl_resource_set_implementation(resource, |
| 4503 | &desktop_shell_implementation, |
| 4504 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4505 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4506 | |
| 4507 | if (version < 2) |
| 4508 | shell_fade_startup(shell); |
| 4509 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4510 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4511 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4512 | |
| 4513 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4514 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4515 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4516 | } |
| 4517 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4518 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4519 | 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] | 4520 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4521 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4522 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4523 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4524 | if (width == 0) |
| 4525 | return; |
| 4526 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4527 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4528 | if (!shell->locked) |
| 4529 | return; |
| 4530 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4531 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4532 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4533 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4534 | if (wl_list_empty(&view->layer_link)) { |
| 4535 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4536 | &view->layer_link); |
| 4537 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4538 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4539 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4540 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4541 | } |
| 4542 | } |
| 4543 | |
| 4544 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4545 | screensaver_set_surface(struct wl_client *client, |
| 4546 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4547 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4548 | struct wl_resource *output_resource) |
| 4549 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4550 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4551 | struct weston_surface *surface = |
| 4552 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4553 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4554 | struct weston_view *view, *next; |
| 4555 | |
| 4556 | /* Make sure we only have one view */ |
| 4557 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4558 | weston_view_destroy(view); |
| 4559 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4560 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4561 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4562 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4563 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4564 | } |
| 4565 | |
| 4566 | static const struct screensaver_interface screensaver_implementation = { |
| 4567 | screensaver_set_surface |
| 4568 | }; |
| 4569 | |
| 4570 | static void |
| 4571 | unbind_screensaver(struct wl_resource *resource) |
| 4572 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4573 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4574 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4575 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | static void |
| 4579 | bind_screensaver(struct wl_client *client, |
| 4580 | void *data, uint32_t version, uint32_t id) |
| 4581 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4582 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4583 | struct wl_resource *resource; |
| 4584 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4585 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4586 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4587 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4588 | wl_resource_set_implementation(resource, |
| 4589 | &screensaver_implementation, |
| 4590 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4591 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4592 | return; |
| 4593 | } |
| 4594 | |
| 4595 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4596 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4597 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4598 | } |
| 4599 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4600 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4601 | 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] | 4602 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4603 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4604 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4605 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4606 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4607 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4608 | if (width == 0) |
| 4609 | return; |
| 4610 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4611 | if (!weston_surface_is_mapped(surface)) { |
| 4612 | if (!shell->showing_input_panels) |
| 4613 | return; |
| 4614 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4615 | show_surface = 1; |
| 4616 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4617 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4618 | 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] | 4619 | |
| 4620 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4621 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4622 | 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] | 4623 | } else { |
Rob Bradford | bdeb5d2 | 2013-07-11 13:20:53 +0100 | [diff] [blame] | 4624 | x = ip_surface->output->x + (ip_surface->output->width - width) / 2; |
| 4625 | y = ip_surface->output->y + ip_surface->output->height - height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4626 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4627 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4628 | weston_view_configure(ip_surface->view, x, y, width, height); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4629 | |
| 4630 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4631 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4632 | &ip_surface->view->layer_link); |
| 4633 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4634 | weston_surface_damage(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4635 | 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] | 4636 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4640 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4641 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4642 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4643 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4644 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4645 | wl_list_remove(&input_panel_surface->link); |
| 4646 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4647 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4648 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4649 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4650 | free(input_panel_surface); |
| 4651 | } |
| 4652 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4653 | static struct input_panel_surface * |
| 4654 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4655 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4656 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4657 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4658 | } else { |
| 4659 | return NULL; |
| 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | static void |
| 4664 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4665 | { |
| 4666 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4667 | struct input_panel_surface, |
| 4668 | surface_destroy_listener); |
| 4669 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4670 | if (ipsurface->resource) { |
| 4671 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4672 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4673 | destroy_input_panel_surface(ipsurface); |
| 4674 | } |
| 4675 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4676 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4677 | static struct input_panel_surface * |
| 4678 | create_input_panel_surface(struct desktop_shell *shell, |
| 4679 | struct weston_surface *surface) |
| 4680 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4681 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4682 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4683 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4684 | if (!input_panel_surface) |
| 4685 | return NULL; |
| 4686 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4687 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4688 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4689 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4690 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4691 | |
| 4692 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4693 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4694 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4695 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4696 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4697 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4698 | &input_panel_surface->surface_destroy_listener); |
| 4699 | |
| 4700 | wl_list_init(&input_panel_surface->link); |
| 4701 | |
| 4702 | return input_panel_surface; |
| 4703 | } |
| 4704 | |
| 4705 | static void |
| 4706 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4707 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4708 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4709 | uint32_t position) |
| 4710 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4711 | struct input_panel_surface *input_panel_surface = |
| 4712 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4713 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4714 | |
| 4715 | wl_list_insert(&shell->input_panel.surfaces, |
| 4716 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4717 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4718 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4719 | input_panel_surface->panel = 0; |
| 4720 | } |
| 4721 | |
| 4722 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4723 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4724 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4725 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4726 | struct input_panel_surface *input_panel_surface = |
| 4727 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4728 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4729 | |
| 4730 | wl_list_insert(&shell->input_panel.surfaces, |
| 4731 | &input_panel_surface->link); |
| 4732 | |
| 4733 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4734 | } |
| 4735 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4736 | 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] | 4737 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4738 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4739 | }; |
| 4740 | |
| 4741 | static void |
| 4742 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4743 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4744 | struct input_panel_surface *ipsurf = |
| 4745 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4746 | |
| 4747 | destroy_input_panel_surface(ipsurf); |
| 4748 | } |
| 4749 | |
| 4750 | static void |
| 4751 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4752 | struct wl_resource *resource, |
| 4753 | uint32_t id, |
| 4754 | struct wl_resource *surface_resource) |
| 4755 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4756 | struct weston_surface *surface = |
| 4757 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4758 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4759 | struct input_panel_surface *ipsurf; |
| 4760 | |
| 4761 | if (get_input_panel_surface(surface)) { |
| 4762 | wl_resource_post_error(surface_resource, |
| 4763 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4764 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4765 | return; |
| 4766 | } |
| 4767 | |
| 4768 | ipsurf = create_input_panel_surface(shell, surface); |
| 4769 | if (!ipsurf) { |
| 4770 | wl_resource_post_error(surface_resource, |
| 4771 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4772 | "surface->configure already set"); |
| 4773 | return; |
| 4774 | } |
| 4775 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4776 | ipsurf->resource = |
| 4777 | wl_resource_create(client, |
| 4778 | &wl_input_panel_surface_interface, 1, id); |
| 4779 | wl_resource_set_implementation(ipsurf->resource, |
| 4780 | &input_panel_surface_implementation, |
| 4781 | ipsurf, |
| 4782 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4783 | } |
| 4784 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4785 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4786 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4787 | }; |
| 4788 | |
| 4789 | static void |
| 4790 | unbind_input_panel(struct wl_resource *resource) |
| 4791 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4792 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4793 | |
| 4794 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4795 | } |
| 4796 | |
| 4797 | static void |
| 4798 | bind_input_panel(struct wl_client *client, |
| 4799 | void *data, uint32_t version, uint32_t id) |
| 4800 | { |
| 4801 | struct desktop_shell *shell = data; |
| 4802 | struct wl_resource *resource; |
| 4803 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4804 | resource = wl_resource_create(client, |
| 4805 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4806 | |
| 4807 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4808 | wl_resource_set_implementation(resource, |
| 4809 | &input_panel_implementation, |
| 4810 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4811 | shell->input_panel.binding = resource; |
| 4812 | return; |
| 4813 | } |
| 4814 | |
| 4815 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4816 | "interface object already bound"); |
| 4817 | wl_resource_destroy(resource); |
| 4818 | } |
| 4819 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4820 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4821 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4822 | struct weston_surface *current; |
| 4823 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4824 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4825 | }; |
| 4826 | |
| 4827 | static void |
| 4828 | switcher_next(struct switcher *switcher) |
| 4829 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4830 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4831 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4832 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4833 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4834 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4835 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 4836 | switch (get_shell_surface_type(view->surface)) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4837 | case SHELL_SURFACE_TOPLEVEL: |
| 4838 | case SHELL_SURFACE_FULLSCREEN: |
| 4839 | case SHELL_SURFACE_MAXIMIZED: |
| 4840 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4841 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4842 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4843 | next = view->surface; |
| 4844 | prev = view->surface; |
| 4845 | view->alpha = 0.25; |
| 4846 | weston_view_geometry_dirty(view); |
| 4847 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4848 | break; |
| 4849 | default: |
| 4850 | break; |
| 4851 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4852 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4853 | if (is_black_surface(view->surface, NULL)) { |
| 4854 | view->alpha = 0.25; |
| 4855 | weston_view_geometry_dirty(view); |
| 4856 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4857 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | if (next == NULL) |
| 4861 | next = first; |
| 4862 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4863 | if (next == NULL) |
| 4864 | return; |
| 4865 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4866 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4867 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4868 | |
| 4869 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4870 | wl_list_for_each(view, &next->views, surface_link) |
| 4871 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4872 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4873 | shsurf = get_shell_surface(switcher->current); |
| 4874 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4875 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4876 | } |
| 4877 | |
| 4878 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4879 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4880 | { |
| 4881 | struct switcher *switcher = |
| 4882 | container_of(listener, struct switcher, listener); |
| 4883 | |
| 4884 | switcher_next(switcher); |
| 4885 | } |
| 4886 | |
| 4887 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4888 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4889 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4890 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4891 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4892 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4893 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4894 | 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] | 4895 | if (is_focus_view(view)) |
| 4896 | continue; |
| 4897 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4898 | view->alpha = 1.0; |
| 4899 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4900 | } |
| 4901 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4902 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4903 | activate(switcher->shell, switcher->current, |
| 4904 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4905 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4906 | weston_keyboard_end_grab(keyboard); |
| 4907 | if (keyboard->input_method_resource) |
| 4908 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4909 | free(switcher); |
| 4910 | } |
| 4911 | |
| 4912 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4913 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4914 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4915 | { |
| 4916 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4917 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4918 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4919 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4920 | switcher_next(switcher); |
| 4921 | } |
| 4922 | |
| 4923 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4924 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4925 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4926 | uint32_t mods_locked, uint32_t group) |
| 4927 | { |
| 4928 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4929 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4930 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4931 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4932 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4933 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4934 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4935 | static void |
| 4936 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4937 | { |
| 4938 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4939 | |
| 4940 | switcher_destroy(switcher); |
| 4941 | } |
| 4942 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4943 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4944 | switcher_key, |
| 4945 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4946 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4947 | }; |
| 4948 | |
| 4949 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4950 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4951 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4952 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4953 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4954 | struct switcher *switcher; |
| 4955 | |
| 4956 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4957 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4958 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4959 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4960 | wl_list_init(&switcher->listener.link); |
| 4961 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4962 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4963 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4964 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4965 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 4966 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4967 | switcher_next(switcher); |
| 4968 | } |
| 4969 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4970 | struct exposay_surface { |
| 4971 | struct desktop_shell *shell; |
| 4972 | struct weston_surface *surface; |
| 4973 | struct weston_view *view; |
| 4974 | struct wl_list link; |
| 4975 | |
| 4976 | int x; |
| 4977 | int y; |
| 4978 | int width; |
| 4979 | int height; |
| 4980 | double scale; |
| 4981 | |
| 4982 | int row; |
| 4983 | int column; |
| 4984 | |
| 4985 | /* The animations only apply a transformation for their own lifetime, |
| 4986 | * and don't have an option to indefinitely maintain the |
| 4987 | * transformation in a steady state - so, we apply our own once the |
| 4988 | * animation has finished. */ |
| 4989 | struct weston_transform transform; |
| 4990 | }; |
| 4991 | |
| 4992 | static void exposay_set_state(struct desktop_shell *shell, |
| 4993 | enum exposay_target_state state, |
| 4994 | struct weston_seat *seat); |
| 4995 | static void exposay_check_state(struct desktop_shell *shell); |
| 4996 | |
| 4997 | static void |
| 4998 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 4999 | { |
| 5000 | shell->exposay.in_flight++; |
| 5001 | } |
| 5002 | |
| 5003 | static void |
| 5004 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5005 | { |
| 5006 | if (--shell->exposay.in_flight > 0) |
| 5007 | return; |
| 5008 | |
| 5009 | exposay_check_state(shell); |
| 5010 | } |
| 5011 | |
| 5012 | static void |
| 5013 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5014 | { |
| 5015 | struct exposay_surface *esurface = data; |
| 5016 | |
| 5017 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5018 | &esurface->transform.link); |
| 5019 | weston_matrix_init(&esurface->transform.matrix); |
| 5020 | weston_matrix_scale(&esurface->transform.matrix, |
| 5021 | esurface->scale, esurface->scale, 1.0f); |
| 5022 | weston_matrix_translate(&esurface->transform.matrix, |
| 5023 | esurface->x - esurface->view->geometry.x, |
| 5024 | esurface->y - esurface->view->geometry.y, |
| 5025 | 0); |
| 5026 | |
| 5027 | weston_view_geometry_dirty(esurface->view); |
| 5028 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5029 | |
| 5030 | exposay_in_flight_dec(esurface->shell); |
| 5031 | } |
| 5032 | |
| 5033 | static void |
| 5034 | exposay_animate_in(struct exposay_surface *esurface) |
| 5035 | { |
| 5036 | exposay_in_flight_inc(esurface->shell); |
| 5037 | |
| 5038 | weston_move_scale_run(esurface->view, |
| 5039 | esurface->x - esurface->view->geometry.x, |
| 5040 | esurface->y - esurface->view->geometry.y, |
| 5041 | 1.0, esurface->scale, 0, |
| 5042 | exposay_animate_in_done, esurface); |
| 5043 | } |
| 5044 | |
| 5045 | static void |
| 5046 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5047 | { |
| 5048 | struct exposay_surface *esurface = data; |
| 5049 | struct desktop_shell *shell = esurface->shell; |
| 5050 | |
| 5051 | wl_list_remove(&esurface->link); |
| 5052 | free(esurface); |
| 5053 | |
| 5054 | exposay_in_flight_dec(shell); |
| 5055 | } |
| 5056 | |
| 5057 | static void |
| 5058 | exposay_animate_out(struct exposay_surface *esurface) |
| 5059 | { |
| 5060 | exposay_in_flight_inc(esurface->shell); |
| 5061 | |
| 5062 | /* Remove the static transformation set up by |
| 5063 | * exposay_transform_in_done(). */ |
| 5064 | wl_list_remove(&esurface->transform.link); |
| 5065 | weston_view_geometry_dirty(esurface->view); |
| 5066 | |
| 5067 | weston_move_scale_run(esurface->view, |
| 5068 | esurface->x - esurface->view->geometry.x, |
| 5069 | esurface->y - esurface->view->geometry.y, |
| 5070 | 1.0, esurface->scale, 1, |
| 5071 | exposay_animate_out_done, esurface); |
| 5072 | } |
| 5073 | |
| 5074 | static void |
| 5075 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5076 | struct exposay_surface *esurface) |
| 5077 | { |
| 5078 | struct weston_view *view = NULL; |
| 5079 | |
| 5080 | if (esurface) { |
| 5081 | shell->exposay.row_current = esurface->row; |
| 5082 | shell->exposay.column_current = esurface->column; |
| 5083 | view = esurface->view; |
| 5084 | } |
| 5085 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5086 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5087 | shell->exposay.focus_current = view; |
| 5088 | } |
| 5089 | |
| 5090 | static int |
| 5091 | exposay_is_animating(struct desktop_shell *shell) |
| 5092 | { |
| 5093 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5094 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5095 | return 0; |
| 5096 | |
| 5097 | return (shell->exposay.in_flight > 0); |
| 5098 | } |
| 5099 | |
| 5100 | static void |
| 5101 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5102 | { |
| 5103 | struct exposay_surface *esurface; |
| 5104 | |
| 5105 | if (exposay_is_animating(shell)) |
| 5106 | return; |
| 5107 | |
| 5108 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5109 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5110 | continue; |
| 5111 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5112 | continue; |
| 5113 | |
| 5114 | exposay_highlight_surface(shell, esurface); |
| 5115 | return; |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5120 | * aspect ratio into account really. Also needs to be notified of surface |
| 5121 | * addition and removal and adjust layout/animate accordingly. */ |
| 5122 | static enum exposay_layout_state |
| 5123 | exposay_layout(struct desktop_shell *shell) |
| 5124 | { |
| 5125 | struct workspace *workspace = shell->exposay.workspace; |
| 5126 | struct weston_compositor *compositor = shell->compositor; |
| 5127 | struct weston_output *output = get_default_output(compositor); |
| 5128 | struct weston_view *view; |
| 5129 | struct exposay_surface *esurface; |
| 5130 | int w, h; |
| 5131 | int i; |
| 5132 | int last_row_removed = 0; |
| 5133 | |
| 5134 | wl_list_init(&shell->exposay.surface_list); |
| 5135 | |
| 5136 | shell->exposay.num_surfaces = 0; |
| 5137 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5138 | if (!get_shell_surface(view->surface)) |
| 5139 | continue; |
| 5140 | shell->exposay.num_surfaces++; |
| 5141 | } |
| 5142 | |
| 5143 | if (shell->exposay.num_surfaces == 0) { |
| 5144 | shell->exposay.grid_size = 0; |
| 5145 | shell->exposay.hpadding_outer = 0; |
| 5146 | shell->exposay.vpadding_outer = 0; |
| 5147 | shell->exposay.padding_inner = 0; |
| 5148 | shell->exposay.surface_size = 0; |
| 5149 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5150 | } |
| 5151 | |
| 5152 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5153 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5154 | * around the outside and 80px internal padding between surfaces, and |
| 5155 | * maximise the area made available to surfaces after this, but only |
| 5156 | * to a maximum of 1/3rd the total output size. |
| 5157 | * |
| 5158 | * If we can't make a square grid, add one extra row at the bottom |
| 5159 | * which will have a smaller number of columns. |
| 5160 | * |
| 5161 | * XXX: Surely there has to be a better way to express this maths, |
| 5162 | * right?! |
| 5163 | */ |
| 5164 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5165 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5166 | shell->exposay.grid_size++; |
| 5167 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5168 | |
| 5169 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5170 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5171 | shell->exposay.padding_inner = 80; |
| 5172 | |
| 5173 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5174 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5175 | w /= shell->exposay.grid_size; |
| 5176 | |
| 5177 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5178 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5179 | h /= shell->exposay.grid_size; |
| 5180 | |
| 5181 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5182 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5183 | shell->exposay.surface_size = output->width / 2; |
| 5184 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5185 | shell->exposay.surface_size = output->height / 2; |
| 5186 | |
| 5187 | i = 0; |
| 5188 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5189 | int pad; |
| 5190 | |
| 5191 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5192 | |
| 5193 | if (!get_shell_surface(view->surface)) |
| 5194 | continue; |
| 5195 | |
| 5196 | esurface = malloc(sizeof(*esurface)); |
| 5197 | if (!esurface) { |
| 5198 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5199 | shell->exposay.seat); |
| 5200 | break; |
| 5201 | } |
| 5202 | |
| 5203 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5204 | esurface->shell = shell; |
| 5205 | esurface->view = view; |
| 5206 | |
| 5207 | esurface->row = i / shell->exposay.grid_size; |
| 5208 | esurface->column = i % shell->exposay.grid_size; |
| 5209 | |
| 5210 | esurface->x = shell->exposay.hpadding_outer; |
| 5211 | esurface->x += pad * esurface->column; |
| 5212 | esurface->y = shell->exposay.vpadding_outer; |
| 5213 | esurface->y += pad * esurface->row; |
| 5214 | |
| 5215 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5216 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5217 | |
| 5218 | if (view->geometry.width > view->geometry.height) |
| 5219 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.width; |
| 5220 | else |
| 5221 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.height; |
| 5222 | esurface->width = view->geometry.width * esurface->scale; |
| 5223 | esurface->height = view->geometry.height * esurface->scale; |
| 5224 | |
| 5225 | if (shell->exposay.focus_current == esurface->view) |
| 5226 | exposay_highlight_surface(shell, esurface); |
| 5227 | |
| 5228 | exposay_animate_in(esurface); |
| 5229 | |
| 5230 | i++; |
| 5231 | } |
| 5232 | |
| 5233 | weston_compositor_schedule_repaint(shell->compositor); |
| 5234 | |
| 5235 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5236 | } |
| 5237 | |
| 5238 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5239 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 5240 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5241 | { |
| 5242 | struct desktop_shell *shell = |
| 5243 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5244 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5245 | weston_pointer_move(grab->pointer, x, y); |
| 5246 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5247 | exposay_pick(shell, |
| 5248 | wl_fixed_to_int(grab->pointer->x), |
| 5249 | wl_fixed_to_int(grab->pointer->y)); |
| 5250 | } |
| 5251 | |
| 5252 | static void |
| 5253 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5254 | uint32_t state_w) |
| 5255 | { |
| 5256 | struct desktop_shell *shell = |
| 5257 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5258 | struct weston_seat *seat = grab->pointer->seat; |
| 5259 | enum wl_pointer_button_state state = state_w; |
| 5260 | |
| 5261 | if (button != BTN_LEFT) |
| 5262 | return; |
| 5263 | |
| 5264 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5265 | * releasing on a different surface. */ |
| 5266 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5267 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5268 | return; |
| 5269 | } |
| 5270 | |
| 5271 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5272 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5273 | else |
| 5274 | shell->exposay.clicked = NULL; |
| 5275 | } |
| 5276 | |
| 5277 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5278 | noop_grab_focus, |
| 5279 | exposay_motion, |
| 5280 | exposay_button, |
| 5281 | }; |
| 5282 | |
| 5283 | static int |
| 5284 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5285 | { |
| 5286 | struct exposay_surface *esurface; |
| 5287 | |
| 5288 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5289 | if (esurface->row != row || esurface->column != column) |
| 5290 | continue; |
| 5291 | |
| 5292 | exposay_highlight_surface(shell, esurface); |
| 5293 | return 1; |
| 5294 | } |
| 5295 | |
| 5296 | return 0; |
| 5297 | } |
| 5298 | |
| 5299 | static void |
| 5300 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5301 | uint32_t state_w) |
| 5302 | { |
| 5303 | struct weston_seat *seat = grab->keyboard->seat; |
| 5304 | struct desktop_shell *shell = |
| 5305 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5306 | enum wl_keyboard_key_state state = state_w; |
| 5307 | |
| 5308 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5309 | return; |
| 5310 | |
| 5311 | switch (key) { |
| 5312 | case KEY_ESC: |
| 5313 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5314 | break; |
| 5315 | case KEY_ENTER: |
| 5316 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5317 | break; |
| 5318 | case KEY_UP: |
| 5319 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5320 | shell->exposay.column_current); |
| 5321 | break; |
| 5322 | case KEY_DOWN: |
| 5323 | /* Special case for trying to move to the bottom row when it |
| 5324 | * has fewer items than all the others. */ |
| 5325 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5326 | shell->exposay.column_current) && |
| 5327 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5328 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5329 | (shell->exposay.num_surfaces % |
| 5330 | shell->exposay.grid_size) - 1); |
| 5331 | } |
| 5332 | break; |
| 5333 | case KEY_LEFT: |
| 5334 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5335 | shell->exposay.column_current - 1); |
| 5336 | break; |
| 5337 | case KEY_RIGHT: |
| 5338 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5339 | shell->exposay.column_current + 1); |
| 5340 | break; |
| 5341 | case KEY_TAB: |
| 5342 | /* Try to move right, then down (and to the leftmost column), |
| 5343 | * then if all else fails, to the top left. */ |
| 5344 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5345 | shell->exposay.column_current + 1) && |
| 5346 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5347 | exposay_maybe_move(shell, 0, 0); |
| 5348 | break; |
| 5349 | default: |
| 5350 | break; |
| 5351 | } |
| 5352 | } |
| 5353 | |
| 5354 | static void |
| 5355 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5356 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5357 | uint32_t mods_locked, uint32_t group) |
| 5358 | { |
| 5359 | } |
| 5360 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5361 | static void |
| 5362 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 5363 | { |
| 5364 | struct desktop_shell *shell = |
| 5365 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5366 | |
| 5367 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5368 | } |
| 5369 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5370 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5371 | exposay_key, |
| 5372 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5373 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5374 | }; |
| 5375 | |
| 5376 | /** |
| 5377 | * Called when the transition from overview -> inactive has completed. |
| 5378 | */ |
| 5379 | static enum exposay_layout_state |
| 5380 | exposay_set_inactive(struct desktop_shell *shell) |
| 5381 | { |
| 5382 | struct weston_seat *seat = shell->exposay.seat; |
| 5383 | |
| 5384 | weston_keyboard_end_grab(seat->keyboard); |
| 5385 | weston_pointer_end_grab(seat->pointer); |
| 5386 | if (seat->keyboard->input_method_resource) |
| 5387 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5388 | |
| 5389 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5390 | } |
| 5391 | |
| 5392 | /** |
| 5393 | * Begins the transition from overview to inactive. */ |
| 5394 | static enum exposay_layout_state |
| 5395 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5396 | { |
| 5397 | struct exposay_surface *esurface; |
| 5398 | |
| 5399 | /* Call activate() before we start the animations to avoid |
| 5400 | * animating back the old state and then immediately transitioning |
| 5401 | * to the new. */ |
| 5402 | if (switch_focus && shell->exposay.focus_current) |
| 5403 | activate(shell, shell->exposay.focus_current->surface, |
| 5404 | shell->exposay.seat); |
| 5405 | else if (shell->exposay.focus_prev) |
| 5406 | activate(shell, shell->exposay.focus_prev->surface, |
| 5407 | shell->exposay.seat); |
| 5408 | |
| 5409 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5410 | exposay_animate_out(esurface); |
| 5411 | weston_compositor_schedule_repaint(shell->compositor); |
| 5412 | |
| 5413 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5414 | } |
| 5415 | |
| 5416 | static enum exposay_layout_state |
| 5417 | exposay_transition_active(struct desktop_shell *shell) |
| 5418 | { |
| 5419 | struct weston_seat *seat = shell->exposay.seat; |
| 5420 | |
| 5421 | shell->exposay.workspace = get_current_workspace(shell); |
| 5422 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5423 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5424 | shell->exposay.clicked = NULL; |
| 5425 | wl_list_init(&shell->exposay.surface_list); |
| 5426 | |
| 5427 | lower_fullscreen_layer(shell); |
| 5428 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5429 | weston_keyboard_start_grab(seat->keyboard, |
| 5430 | &shell->exposay.grab_kbd); |
| 5431 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5432 | |
| 5433 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5434 | weston_pointer_start_grab(seat->pointer, |
| 5435 | &shell->exposay.grab_ptr); |
| 5436 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5437 | seat->pointer->x, seat->pointer->y); |
| 5438 | |
| 5439 | return exposay_layout(shell); |
| 5440 | } |
| 5441 | |
| 5442 | static void |
| 5443 | exposay_check_state(struct desktop_shell *shell) |
| 5444 | { |
| 5445 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5446 | int do_switch = 0; |
| 5447 | |
| 5448 | /* Don't do anything whilst animations are running, just store up |
| 5449 | * target state changes and only act on them when the animations have |
| 5450 | * completed. */ |
| 5451 | if (exposay_is_animating(shell)) |
| 5452 | return; |
| 5453 | |
| 5454 | switch (shell->exposay.state_target) { |
| 5455 | case EXPOSAY_TARGET_OVERVIEW: |
| 5456 | switch (shell->exposay.state_cur) { |
| 5457 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5458 | goto out; |
| 5459 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5460 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5461 | break; |
| 5462 | default: |
| 5463 | state_new = exposay_transition_active(shell); |
| 5464 | break; |
| 5465 | } |
| 5466 | break; |
| 5467 | |
| 5468 | case EXPOSAY_TARGET_SWITCH: |
| 5469 | do_switch = 1; /* fallthrough */ |
| 5470 | case EXPOSAY_TARGET_CANCEL: |
| 5471 | switch (shell->exposay.state_cur) { |
| 5472 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5473 | goto out; |
| 5474 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5475 | state_new = exposay_set_inactive(shell); |
| 5476 | break; |
| 5477 | default: |
| 5478 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5479 | break; |
| 5480 | } |
| 5481 | |
| 5482 | break; |
| 5483 | } |
| 5484 | |
| 5485 | out: |
| 5486 | shell->exposay.state_cur = state_new; |
| 5487 | } |
| 5488 | |
| 5489 | static void |
| 5490 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5491 | struct weston_seat *seat) |
| 5492 | { |
| 5493 | shell->exposay.state_target = state; |
| 5494 | shell->exposay.seat = seat; |
| 5495 | exposay_check_state(shell); |
| 5496 | } |
| 5497 | |
| 5498 | static void |
| 5499 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5500 | void *data) |
| 5501 | { |
| 5502 | struct desktop_shell *shell = data; |
| 5503 | |
| 5504 | if (shell->exposay.state_target == EXPOSAY_TARGET_OVERVIEW) |
| 5505 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5506 | else |
| 5507 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
| 5508 | } |
| 5509 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5510 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5511 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5512 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5513 | { |
| 5514 | struct weston_compositor *compositor = data; |
| 5515 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5516 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5517 | |
| 5518 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5519 | * control on the primary display. We'd have to extend later if we |
| 5520 | * ever get support for setting backlights on random desktop LCD |
| 5521 | * panels though */ |
| 5522 | output = get_default_output(compositor); |
| 5523 | if (!output) |
| 5524 | return; |
| 5525 | |
| 5526 | if (!output->set_backlight) |
| 5527 | return; |
| 5528 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5529 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5530 | backlight_new = output->backlight_current - 25; |
| 5531 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5532 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5533 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5534 | if (backlight_new < 5) |
| 5535 | backlight_new = 5; |
| 5536 | if (backlight_new > 255) |
| 5537 | backlight_new = 255; |
| 5538 | |
| 5539 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5540 | output->set_backlight(output, output->backlight_current); |
| 5541 | } |
| 5542 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5543 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5544 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5545 | struct weston_seat *seat; |
| 5546 | uint32_t key[2]; |
| 5547 | int key_released[2]; |
| 5548 | }; |
| 5549 | |
| 5550 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5551 | 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] | 5552 | uint32_t key, uint32_t state) |
| 5553 | { |
| 5554 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5555 | struct weston_compositor *ec = db->seat->compositor; |
| 5556 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5557 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5558 | uint32_t serial; |
| 5559 | int send = 0, terminate = 0; |
| 5560 | int check_binding = 1; |
| 5561 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5562 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5563 | |
| 5564 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5565 | /* Do not run bindings on key releases */ |
| 5566 | check_binding = 0; |
| 5567 | |
| 5568 | for (i = 0; i < 2; i++) |
| 5569 | if (key == db->key[i]) |
| 5570 | db->key_released[i] = 1; |
| 5571 | |
| 5572 | if (db->key_released[0] && db->key_released[1]) { |
| 5573 | /* All key releases been swalled so end the grab */ |
| 5574 | terminate = 1; |
| 5575 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5576 | /* Should not swallow release of other keys */ |
| 5577 | send = 1; |
| 5578 | } |
| 5579 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5580 | /* Do not check bindings for the first press of the binding |
| 5581 | * key. This allows it to be used as a debug shortcut. |
| 5582 | * We still need to swallow this event. */ |
| 5583 | check_binding = 0; |
| 5584 | } else if (db->key[1]) { |
| 5585 | /* If we already ran a binding don't process another one since |
| 5586 | * we can't keep track of all the binding keys that were |
| 5587 | * pressed in order to swallow the release events. */ |
| 5588 | send = 1; |
| 5589 | check_binding = 0; |
| 5590 | } |
| 5591 | |
| 5592 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5593 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5594 | key, state)) { |
| 5595 | /* We ran a binding so swallow the press and keep the |
| 5596 | * grab to swallow the released too. */ |
| 5597 | send = 0; |
| 5598 | terminate = 0; |
| 5599 | db->key[1] = key; |
| 5600 | } else { |
| 5601 | /* Terminate the grab since the key pressed is not a |
| 5602 | * debug binding key. */ |
| 5603 | send = 1; |
| 5604 | terminate = 1; |
| 5605 | } |
| 5606 | } |
| 5607 | |
| 5608 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5609 | serial = wl_display_next_serial(display); |
| 5610 | resource_list = &grab->keyboard->focus_resource_list; |
| 5611 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5612 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5617 | weston_keyboard_end_grab(grab->keyboard); |
| 5618 | if (grab->keyboard->input_method_resource) |
| 5619 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5620 | free(db); |
| 5621 | } |
| 5622 | } |
| 5623 | |
| 5624 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5625 | 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] | 5626 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5627 | uint32_t mods_locked, uint32_t group) |
| 5628 | { |
| 5629 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5630 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5631 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5632 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5633 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5634 | wl_resource_for_each(resource, resource_list) { |
| 5635 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5636 | mods_latched, mods_locked, group); |
| 5637 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5638 | } |
| 5639 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5640 | static void |
| 5641 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5642 | { |
| 5643 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5644 | |
| 5645 | weston_keyboard_end_grab(grab->keyboard); |
| 5646 | free(db); |
| 5647 | } |
| 5648 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5649 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5650 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5651 | debug_binding_modifiers, |
| 5652 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5653 | }; |
| 5654 | |
| 5655 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5656 | 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] | 5657 | { |
| 5658 | struct debug_binding_grab *grab; |
| 5659 | |
| 5660 | grab = calloc(1, sizeof *grab); |
| 5661 | if (!grab) |
| 5662 | return; |
| 5663 | |
| 5664 | grab->seat = (struct weston_seat *) seat; |
| 5665 | grab->key[0] = key; |
| 5666 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5667 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5668 | } |
| 5669 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5670 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5671 | 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] | 5672 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5673 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5674 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5675 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5676 | struct desktop_shell *shell = data; |
| 5677 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5678 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5679 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5680 | focus_surface = seat->keyboard->focus; |
| 5681 | if (!focus_surface) |
| 5682 | return; |
| 5683 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5684 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5685 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5686 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5687 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5688 | |
| 5689 | /* Skip clients that we launched ourselves (the credentials of |
| 5690 | * the socketpair is ours) */ |
| 5691 | if (pid == getpid()) |
| 5692 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5693 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5694 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5695 | } |
| 5696 | |
| 5697 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5698 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5699 | uint32_t key, void *data) |
| 5700 | { |
| 5701 | struct desktop_shell *shell = data; |
| 5702 | unsigned int new_index = shell->workspaces.current; |
| 5703 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5704 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5705 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5706 | if (new_index != 0) |
| 5707 | new_index--; |
| 5708 | |
| 5709 | change_workspace(shell, new_index); |
| 5710 | } |
| 5711 | |
| 5712 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5713 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5714 | uint32_t key, void *data) |
| 5715 | { |
| 5716 | struct desktop_shell *shell = data; |
| 5717 | unsigned int new_index = shell->workspaces.current; |
| 5718 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5719 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5720 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5721 | if (new_index < shell->workspaces.num - 1) |
| 5722 | new_index++; |
| 5723 | |
| 5724 | change_workspace(shell, new_index); |
| 5725 | } |
| 5726 | |
| 5727 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5728 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5729 | uint32_t key, void *data) |
| 5730 | { |
| 5731 | struct desktop_shell *shell = data; |
| 5732 | unsigned int new_index; |
| 5733 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5734 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5735 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5736 | new_index = key - KEY_F1; |
| 5737 | if (new_index >= shell->workspaces.num) |
| 5738 | new_index = shell->workspaces.num - 1; |
| 5739 | |
| 5740 | change_workspace(shell, new_index); |
| 5741 | } |
| 5742 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5743 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5744 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5745 | uint32_t key, void *data) |
| 5746 | { |
| 5747 | struct desktop_shell *shell = data; |
| 5748 | unsigned int new_index = shell->workspaces.current; |
| 5749 | |
| 5750 | if (shell->locked) |
| 5751 | return; |
| 5752 | |
| 5753 | if (new_index != 0) |
| 5754 | new_index--; |
| 5755 | |
| 5756 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5757 | } |
| 5758 | |
| 5759 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5760 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5761 | uint32_t key, void *data) |
| 5762 | { |
| 5763 | struct desktop_shell *shell = data; |
| 5764 | unsigned int new_index = shell->workspaces.current; |
| 5765 | |
| 5766 | if (shell->locked) |
| 5767 | return; |
| 5768 | |
| 5769 | if (new_index < shell->workspaces.num - 1) |
| 5770 | new_index++; |
| 5771 | |
| 5772 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5773 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5774 | |
| 5775 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5776 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5777 | { |
| 5778 | struct shell_output *output_listener = |
| 5779 | container_of(listener, struct shell_output, destroy_listener); |
| 5780 | |
| 5781 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5782 | wl_list_remove(&output_listener->link); |
| 5783 | free(output_listener); |
| 5784 | } |
| 5785 | |
| 5786 | static void |
| 5787 | create_shell_output(struct desktop_shell *shell, |
| 5788 | struct weston_output *output) |
| 5789 | { |
| 5790 | struct shell_output *shell_output; |
| 5791 | |
| 5792 | shell_output = zalloc(sizeof *shell_output); |
| 5793 | if (shell_output == NULL) |
| 5794 | return; |
| 5795 | |
| 5796 | shell_output->output = output; |
| 5797 | shell_output->shell = shell; |
| 5798 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5799 | wl_signal_add(&output->destroy_signal, |
| 5800 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5801 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | static void |
| 5805 | handle_output_create(struct wl_listener *listener, void *data) |
| 5806 | { |
| 5807 | struct desktop_shell *shell = |
| 5808 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5809 | struct weston_output *output = (struct weston_output *)data; |
| 5810 | |
| 5811 | create_shell_output(shell, output); |
| 5812 | } |
| 5813 | |
| 5814 | static void |
| 5815 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5816 | struct desktop_shell *shell) |
| 5817 | { |
| 5818 | struct weston_output *output; |
| 5819 | |
| 5820 | wl_list_init(&shell->output_list); |
| 5821 | wl_list_for_each(output, &ec->output_list, link) |
| 5822 | create_shell_output(shell, output); |
| 5823 | |
| 5824 | shell->output_create_listener.notify = handle_output_create; |
| 5825 | wl_signal_add(&ec->output_created_signal, |
| 5826 | &shell->output_create_listener); |
| 5827 | } |
| 5828 | |
| 5829 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5830 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5831 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5832 | struct desktop_shell *shell = |
| 5833 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5834 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5835 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5836 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5837 | if (shell->child.client) |
| 5838 | wl_client_destroy(shell->child.client); |
| 5839 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5840 | wl_list_remove(&shell->idle_listener.link); |
| 5841 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5842 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 5843 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5844 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5845 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5846 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5847 | wl_list_remove(&shell_output->link); |
| 5848 | free(shell_output); |
| 5849 | } |
| 5850 | |
| 5851 | wl_list_remove(&shell->output_create_listener.link); |
| 5852 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5853 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5854 | workspace_destroy(*ws); |
| 5855 | wl_array_release(&shell->workspaces.array); |
| 5856 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5857 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame^] | 5858 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5859 | free(shell); |
| 5860 | } |
| 5861 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5862 | static void |
| 5863 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5864 | { |
| 5865 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5866 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5867 | |
| 5868 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5869 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5870 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5871 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 5872 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 5873 | MODIFIER_ALT, |
| 5874 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5875 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5876 | click_to_activate_binding, |
| 5877 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5878 | weston_compositor_add_touch_binding(ec, 0, |
| 5879 | touch_to_activate_binding, |
| 5880 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5881 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5882 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5883 | surface_opacity_binding, NULL); |
| 5884 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5885 | MODIFIER_SUPER, zoom_axis_binding, |
| 5886 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5887 | |
| 5888 | /* configurable bindings */ |
| 5889 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5890 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5891 | zoom_key_binding, NULL); |
| 5892 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5893 | zoom_key_binding, NULL); |
| 5894 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5895 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5896 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5897 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5898 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5899 | |
| 5900 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5901 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5902 | rotate_binding, NULL); |
| 5903 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5904 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5905 | shell); |
| 5906 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5907 | ec); |
| 5908 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5909 | backlight_binding, ec); |
| 5910 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5911 | ec); |
| 5912 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5913 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5914 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5915 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5916 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5917 | workspace_up_binding, shell); |
| 5918 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5919 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5920 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5921 | workspace_move_surface_up_binding, |
| 5922 | shell); |
| 5923 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5924 | workspace_move_surface_down_binding, |
| 5925 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5926 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5927 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 5928 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5929 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5930 | if (shell->workspaces.num > 1) { |
| 5931 | num_workspace_bindings = shell->workspaces.num; |
| 5932 | if (num_workspace_bindings > 6) |
| 5933 | num_workspace_bindings = 6; |
| 5934 | for (i = 0; i < num_workspace_bindings; i++) |
| 5935 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5936 | workspace_f_binding, |
| 5937 | shell); |
| 5938 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5939 | |
| 5940 | /* Debug bindings */ |
| 5941 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5942 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5943 | } |
| 5944 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5945 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5946 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5947 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5948 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5949 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5950 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5951 | struct workspace **pws; |
| 5952 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5953 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5954 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5955 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5956 | if (shell == NULL) |
| 5957 | return -1; |
| 5958 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5959 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5960 | |
| 5961 | shell->destroy_listener.notify = shell_destroy; |
| 5962 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5963 | shell->idle_listener.notify = idle_handler; |
| 5964 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5965 | shell->wake_listener.notify = wake_handler; |
| 5966 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5967 | shell->show_input_panel_listener.notify = show_input_panels; |
| 5968 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 5969 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 5970 | 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] | 5971 | shell->update_input_panel_listener.notify = update_input_panels; |
| 5972 | 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] | 5973 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5974 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5975 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5976 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5977 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5978 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5979 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5980 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5981 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5982 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5983 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5984 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5985 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5986 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5987 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5988 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5989 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5990 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5991 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5992 | |
| 5993 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5994 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5995 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5996 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5997 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5998 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5999 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6000 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6001 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6002 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6003 | if (pws == NULL) |
| 6004 | return -1; |
| 6005 | |
| 6006 | *pws = workspace_create(); |
| 6007 | if (*pws == NULL) |
| 6008 | return -1; |
| 6009 | } |
| 6010 | activate_workspace(shell, 0); |
| 6011 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6012 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6013 | wl_list_init(&shell->workspaces.animation.link); |
| 6014 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6015 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6016 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6017 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6018 | return -1; |
| 6019 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6020 | if (wl_global_create(ec->wl_display, |
| 6021 | &desktop_shell_interface, 2, |
| 6022 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6023 | return -1; |
| 6024 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6025 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6026 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6027 | return -1; |
| 6028 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6029 | 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] | 6030 | shell, bind_input_panel) == NULL) |
| 6031 | return -1; |
| 6032 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6033 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6034 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6035 | return -1; |
| 6036 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6037 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6038 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6039 | setup_output_destroy_handler(ec, shell); |
| 6040 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6041 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6042 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6043 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6044 | shell->screensaver.timer = |
| 6045 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6046 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6047 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6048 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6049 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6050 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6051 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6052 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6053 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6054 | return 0; |
| 6055 | } |