Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
| 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
| 15 | * |
| 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 23 | */ |
| 24 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 29 | #include <stdbool.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 34 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 36 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 37 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 39 | #include "desktop-shell-server-protocol.h" |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 40 | #include "input-method-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 41 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 42 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 43 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 44 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 45 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 46 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 47 | enum animation_type { |
| 48 | ANIMATION_NONE, |
| 49 | |
| 50 | ANIMATION_ZOOM, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 51 | ANIMATION_FADE, |
| 52 | ANIMATION_DIM_LAYER, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 53 | }; |
| 54 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 55 | enum fade_type { |
| 56 | FADE_IN, |
| 57 | FADE_OUT |
| 58 | }; |
| 59 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 60 | enum exposay_target_state { |
| 61 | EXPOSAY_TARGET_OVERVIEW, /* show all windows */ |
| 62 | EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */ |
| 63 | EXPOSAY_TARGET_SWITCH, /* return to normal, switch focus */ |
| 64 | }; |
| 65 | |
| 66 | enum exposay_layout_state { |
| 67 | EXPOSAY_LAYOUT_INACTIVE = 0, /* normal desktop */ |
| 68 | EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE, /* in transition to normal */ |
| 69 | EXPOSAY_LAYOUT_OVERVIEW, /* show all windows */ |
| 70 | EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW, /* in transition to all windows */ |
| 71 | }; |
| 72 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 73 | struct focus_state { |
| 74 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 75 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 76 | struct weston_surface *keyboard_focus; |
| 77 | struct wl_list link; |
| 78 | struct wl_listener seat_destroy_listener; |
| 79 | struct wl_listener surface_destroy_listener; |
| 80 | }; |
| 81 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 82 | struct focus_surface { |
| 83 | struct weston_surface *surface; |
| 84 | struct weston_view *view; |
| 85 | struct weston_transform workspace_transform; |
| 86 | }; |
| 87 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 88 | struct workspace { |
| 89 | struct weston_layer layer; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 90 | |
| 91 | struct wl_list focus_list; |
| 92 | struct wl_listener seat_destroyed_listener; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 93 | |
| 94 | struct focus_surface *fsurf_front; |
| 95 | struct focus_surface *fsurf_back; |
| 96 | struct weston_view_animation *focus_animation; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 99 | struct input_panel_surface { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 100 | struct wl_resource *resource; |
| 101 | struct wl_signal destroy_signal; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 102 | |
| 103 | struct desktop_shell *shell; |
| 104 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 105 | struct wl_list link; |
| 106 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 107 | struct weston_view *view; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 108 | struct wl_listener surface_destroy_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 109 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 110 | struct weston_output *output; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 111 | uint32_t panel; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 114 | struct shell_output { |
| 115 | struct desktop_shell *shell; |
| 116 | struct weston_output *output; |
| 117 | struct wl_listener destroy_listener; |
| 118 | struct wl_list link; |
| 119 | }; |
| 120 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 121 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 122 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 123 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 124 | struct wl_listener idle_listener; |
| 125 | struct wl_listener wake_listener; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 126 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 127 | struct wl_listener show_input_panel_listener; |
| 128 | struct wl_listener hide_input_panel_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 129 | struct wl_listener update_input_panel_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 130 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 131 | struct weston_layer fullscreen_layer; |
| 132 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 133 | struct weston_layer background_layer; |
| 134 | struct weston_layer lock_layer; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 135 | struct weston_layer input_panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 136 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 137 | struct wl_listener pointer_focus_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 138 | struct weston_surface *grab_surface; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 139 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 140 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 141 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 142 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 143 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 144 | |
| 145 | unsigned deathcount; |
| 146 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 147 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 148 | |
| 149 | bool locked; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 150 | bool showing_input_panels; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 151 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 152 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 153 | struct { |
| 154 | struct weston_surface *surface; |
| 155 | pixman_box32_t cursor_rectangle; |
| 156 | } text_input; |
| 157 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 158 | struct weston_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 159 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 160 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 161 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 162 | struct wl_array array; |
| 163 | unsigned int current; |
| 164 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 165 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 166 | struct wl_list client_list; |
| 167 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 168 | struct weston_animation animation; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 169 | struct wl_list anim_sticky_list; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 170 | int anim_dir; |
| 171 | uint32_t anim_timestamp; |
| 172 | double anim_current; |
| 173 | struct workspace *anim_from; |
| 174 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 175 | } workspaces; |
| 176 | |
| 177 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 178 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 179 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 180 | struct wl_resource *binding; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 181 | struct weston_process process; |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 182 | struct wl_event_source *timer; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 183 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 184 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 185 | struct { |
| 186 | struct wl_resource *binding; |
| 187 | struct wl_list surfaces; |
| 188 | } input_panel; |
| 189 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 190 | struct { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 191 | struct weston_view *view; |
| 192 | struct weston_view_animation *animation; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 193 | enum fade_type type; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 194 | struct wl_event_source *startup_timer; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 195 | } fade; |
| 196 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 197 | struct exposay { |
| 198 | /* XXX: Make these exposay_surfaces. */ |
| 199 | struct weston_view *focus_prev; |
| 200 | struct weston_view *focus_current; |
| 201 | struct weston_view *clicked; |
| 202 | struct workspace *workspace; |
| 203 | struct weston_seat *seat; |
| 204 | struct wl_list surface_list; |
| 205 | |
| 206 | struct weston_keyboard_grab grab_kbd; |
| 207 | struct weston_pointer_grab grab_ptr; |
| 208 | |
| 209 | enum exposay_target_state state_target; |
| 210 | enum exposay_layout_state state_cur; |
| 211 | int in_flight; /* number of animations still running */ |
| 212 | |
| 213 | int num_surfaces; |
| 214 | int grid_size; |
| 215 | int surface_size; |
| 216 | |
| 217 | int hpadding_outer; |
| 218 | int vpadding_outer; |
| 219 | int padding_inner; |
| 220 | |
| 221 | int row_current; |
| 222 | int column_current; |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 223 | |
| 224 | bool mod_pressed; |
| 225 | bool mod_invalid; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 226 | } exposay; |
| 227 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 228 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 229 | enum animation_type win_animation_type; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 230 | enum animation_type startup_animation_type; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 231 | enum animation_type focus_animation_type; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 232 | |
| 233 | struct wl_listener output_create_listener; |
| 234 | struct wl_list output_list; |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 235 | |
| 236 | char *client; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 237 | }; |
| 238 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 239 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 240 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 241 | SHELL_SURFACE_TOPLEVEL, |
| 242 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 243 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 244 | SHELL_SURFACE_MAXIMIZED, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 245 | SHELL_SURFACE_POPUP, |
| 246 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 247 | }; |
| 248 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 249 | struct ping_timer { |
| 250 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 251 | uint32_t serial; |
| 252 | }; |
| 253 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 254 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 255 | struct wl_resource *resource; |
| 256 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 257 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 258 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 259 | struct weston_view *view; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 260 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 261 | struct weston_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 262 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 263 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 264 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 265 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 266 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 267 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 268 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 269 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 270 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 271 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 272 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 273 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 274 | } rotation; |
| 275 | |
| 276 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 277 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 278 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 279 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 280 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 281 | } popup; |
| 282 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 283 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 284 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 285 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 286 | } transient; |
| 287 | |
| 288 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 289 | enum wl_shell_surface_fullscreen_method type; |
| 290 | struct weston_transform transform; /* matrix from x, y */ |
| 291 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 292 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 293 | } fullscreen; |
| 294 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 295 | struct ping_timer *ping_timer; |
| 296 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 297 | struct weston_transform workspace_transform; |
| 298 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 299 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 300 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 301 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 302 | |
| 303 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 304 | }; |
| 305 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 306 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 307 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 308 | struct shell_surface *shsurf; |
| 309 | struct wl_listener shsurf_destroy_listener; |
| 310 | }; |
| 311 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 312 | struct shell_touch_grab { |
| 313 | struct weston_touch_grab grab; |
| 314 | struct shell_surface *shsurf; |
| 315 | struct wl_listener shsurf_destroy_listener; |
| 316 | struct weston_touch *touch; |
| 317 | }; |
| 318 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 319 | struct weston_move_grab { |
| 320 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 321 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 322 | }; |
| 323 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 324 | struct weston_touch_move_grab { |
| 325 | struct shell_touch_grab base; |
| 326 | wl_fixed_t dx, dy; |
| 327 | }; |
| 328 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 329 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 330 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 331 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 332 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 333 | float x; |
| 334 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 335 | } center; |
| 336 | }; |
| 337 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 338 | struct shell_seat { |
| 339 | struct weston_seat *seat; |
| 340 | struct wl_listener seat_destroy_listener; |
| 341 | |
| 342 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 343 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 344 | struct wl_list surfaces_list; |
| 345 | struct wl_client *client; |
| 346 | int32_t initial_up; |
| 347 | } popup_grab; |
| 348 | }; |
| 349 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 350 | static void |
| 351 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 352 | struct weston_seat *seat); |
| 353 | |
| 354 | static struct workspace * |
| 355 | get_current_workspace(struct desktop_shell *shell); |
| 356 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 357 | static struct shell_surface * |
| 358 | get_shell_surface(struct weston_surface *surface); |
| 359 | |
| 360 | static struct desktop_shell * |
| 361 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 362 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 363 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 364 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 365 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 366 | static void |
| 367 | shell_fade_startup(struct desktop_shell *shell); |
| 368 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 369 | static struct shell_seat * |
| 370 | get_shell_seat(struct weston_seat *seat); |
| 371 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 372 | static bool |
| 373 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 374 | { |
| 375 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 376 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 377 | |
| 378 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 379 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 380 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 381 | return false; |
| 382 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 383 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 384 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 385 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 386 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 387 | } |
| 388 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 389 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 390 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 391 | { |
| 392 | struct shell_grab *grab; |
| 393 | |
| 394 | grab = container_of(listener, struct shell_grab, |
| 395 | shsurf_destroy_listener); |
| 396 | |
| 397 | grab->shsurf = NULL; |
| 398 | } |
| 399 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 400 | static struct weston_view * |
| 401 | get_default_view(struct weston_surface *surface) |
| 402 | { |
| 403 | struct shell_surface *shsurf; |
| 404 | struct weston_view *view; |
| 405 | |
| 406 | if (!surface || wl_list_empty(&surface->views)) |
| 407 | return NULL; |
| 408 | |
| 409 | shsurf = get_shell_surface(surface); |
| 410 | if (shsurf) |
| 411 | return shsurf->view; |
| 412 | |
| 413 | wl_list_for_each(view, &surface->views, surface_link) |
| 414 | if (weston_view_is_mapped(view)) |
| 415 | return view; |
| 416 | |
| 417 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 418 | } |
| 419 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 420 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 421 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 422 | |
| 423 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 424 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 425 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 426 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 427 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 428 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 429 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 430 | struct desktop_shell *shell = shsurf->shell; |
| 431 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 432 | popup_grab_end(pointer); |
| 433 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 434 | grab->grab.interface = interface; |
| 435 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 436 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 437 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 438 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 439 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 440 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 441 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 442 | if (shell->child.desktop_shell) { |
| 443 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 444 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 445 | weston_pointer_set_focus(pointer, |
| 446 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 447 | wl_fixed_from_int(0), |
| 448 | wl_fixed_from_int(0)); |
| 449 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 453 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 454 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 455 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 456 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 457 | grab->shsurf->grabbed = 0; |
| 458 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 459 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 460 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 464 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 465 | const struct weston_touch_grab_interface *interface, |
| 466 | struct shell_surface *shsurf, |
| 467 | struct weston_touch *touch) |
| 468 | { |
| 469 | struct desktop_shell *shell = shsurf->shell; |
| 470 | |
| 471 | grab->grab.interface = interface; |
| 472 | grab->shsurf = shsurf; |
| 473 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 474 | wl_signal_add(&shsurf->destroy_signal, |
| 475 | &grab->shsurf_destroy_listener); |
| 476 | |
| 477 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 478 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 479 | |
| 480 | weston_touch_start_grab(touch, &grab->grab); |
| 481 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 482 | weston_touch_set_focus(touch->seat, |
| 483 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static void |
| 487 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 488 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 489 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 490 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 491 | grab->shsurf->grabbed = 0; |
| 492 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 493 | |
| 494 | weston_touch_end_grab(grab->touch); |
| 495 | } |
| 496 | |
| 497 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 498 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 499 | struct weston_output *output); |
| 500 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 501 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 502 | get_modifier(char *modifier) |
| 503 | { |
| 504 | if (!modifier) |
| 505 | return MODIFIER_SUPER; |
| 506 | |
| 507 | if (!strcmp("ctrl", modifier)) |
| 508 | return MODIFIER_CTRL; |
| 509 | else if (!strcmp("alt", modifier)) |
| 510 | return MODIFIER_ALT; |
| 511 | else if (!strcmp("super", modifier)) |
| 512 | return MODIFIER_SUPER; |
| 513 | else |
| 514 | return MODIFIER_SUPER; |
| 515 | } |
| 516 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 517 | static enum animation_type |
| 518 | get_animation_type(char *animation) |
| 519 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 520 | if (!strcmp("zoom", animation)) |
| 521 | return ANIMATION_ZOOM; |
| 522 | else if (!strcmp("fade", animation)) |
| 523 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 524 | else if (!strcmp("dim-layer", animation)) |
| 525 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 526 | else |
| 527 | return ANIMATION_NONE; |
| 528 | } |
| 529 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 530 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 531 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 532 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 533 | struct weston_config_section *section; |
| 534 | int duration; |
| 535 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 536 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 537 | section = weston_config_get_section(shell->compositor->config, |
| 538 | "screensaver", NULL, NULL); |
| 539 | weston_config_section_get_string(section, |
| 540 | "path", &shell->screensaver.path, NULL); |
| 541 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 542 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 543 | |
| 544 | section = weston_config_get_section(shell->compositor->config, |
| 545 | "shell", NULL, NULL); |
| 546 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 547 | "client", &s, LIBEXECDIR "/weston-desktop-shell"); |
| 548 | shell->client = s; |
| 549 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 550 | "binding-modifier", &s, "super"); |
| 551 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 552 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 553 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 554 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 555 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 556 | weston_config_section_get_string(section, |
| 557 | "startup-animation", &s, "fade"); |
| 558 | shell->startup_animation_type = get_animation_type(s); |
| 559 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 560 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 561 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 562 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 563 | shell->focus_animation_type = get_animation_type(s); |
| 564 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 565 | weston_config_section_get_uint(section, "num-workspaces", |
| 566 | &shell->workspaces.num, |
| 567 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 568 | } |
| 569 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 570 | static struct weston_output * |
| 571 | get_default_output(struct weston_compositor *compositor) |
| 572 | { |
| 573 | return container_of(compositor->output_list.next, |
| 574 | struct weston_output, link); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | /* no-op func for checking focus surface */ |
| 579 | static void |
| 580 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, |
| 581 | int32_t width, int32_t height) |
| 582 | { |
| 583 | } |
| 584 | |
| 585 | static struct focus_surface * |
| 586 | get_focus_surface(struct weston_surface *surface) |
| 587 | { |
| 588 | if (surface->configure == focus_surface_configure) |
| 589 | return surface->configure_private; |
| 590 | else |
| 591 | return NULL; |
| 592 | } |
| 593 | |
| 594 | static bool |
| 595 | is_focus_surface (struct weston_surface *es) |
| 596 | { |
| 597 | return (es->configure == focus_surface_configure); |
| 598 | } |
| 599 | |
| 600 | static bool |
| 601 | is_focus_view (struct weston_view *view) |
| 602 | { |
| 603 | return is_focus_surface (view->surface); |
| 604 | } |
| 605 | |
| 606 | static struct focus_surface * |
| 607 | create_focus_surface(struct weston_compositor *ec, |
| 608 | struct weston_output *output) |
| 609 | { |
| 610 | struct focus_surface *fsurf = NULL; |
| 611 | struct weston_surface *surface = NULL; |
| 612 | |
| 613 | fsurf = malloc(sizeof *fsurf); |
| 614 | if (!fsurf) |
| 615 | return NULL; |
| 616 | |
| 617 | fsurf->surface = weston_surface_create(ec); |
| 618 | surface = fsurf->surface; |
| 619 | if (surface == NULL) { |
| 620 | free(fsurf); |
| 621 | return NULL; |
| 622 | } |
| 623 | |
| 624 | surface->configure = focus_surface_configure; |
| 625 | surface->output = output; |
| 626 | surface->configure_private = fsurf; |
| 627 | |
| 628 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 629 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 630 | |
| 631 | weston_view_configure(fsurf->view, output->x, output->y, |
| 632 | output->width, output->height); |
| 633 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 634 | pixman_region32_fini(&surface->opaque); |
| 635 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 636 | output->width, output->height); |
| 637 | pixman_region32_fini(&surface->input); |
| 638 | pixman_region32_init(&surface->input); |
| 639 | |
| 640 | wl_list_init(&fsurf->workspace_transform.link); |
| 641 | |
| 642 | return fsurf; |
| 643 | } |
| 644 | |
| 645 | static void |
| 646 | focus_surface_destroy(struct focus_surface *fsurf) |
| 647 | { |
| 648 | weston_surface_destroy(fsurf->surface); |
| 649 | free(fsurf); |
| 650 | } |
| 651 | |
| 652 | static void |
| 653 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 654 | { |
| 655 | struct workspace *ws = data; |
| 656 | |
| 657 | ws->focus_animation = NULL; |
| 658 | } |
| 659 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 660 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 661 | focus_state_destroy(struct focus_state *state) |
| 662 | { |
| 663 | wl_list_remove(&state->seat_destroy_listener.link); |
| 664 | wl_list_remove(&state->surface_destroy_listener.link); |
| 665 | free(state); |
| 666 | } |
| 667 | |
| 668 | static void |
| 669 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 670 | { |
| 671 | struct focus_state *state = container_of(listener, |
| 672 | struct focus_state, |
| 673 | seat_destroy_listener); |
| 674 | |
| 675 | wl_list_remove(&state->link); |
| 676 | focus_state_destroy(state); |
| 677 | } |
| 678 | |
| 679 | static void |
| 680 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 681 | { |
| 682 | struct focus_state *state = container_of(listener, |
| 683 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 684 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 685 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 686 | struct weston_surface *main_surface, *next; |
| 687 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 688 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 689 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 690 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 691 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 692 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 693 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 694 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 695 | if (is_focus_view(view)) |
| 696 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 697 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 698 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 699 | break; |
| 700 | } |
| 701 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 702 | /* if the focus was a sub-surface, activate its main surface */ |
| 703 | if (main_surface != state->keyboard_focus) |
| 704 | next = main_surface; |
| 705 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 706 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 707 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 708 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 709 | activate(shell, next, state->seat); |
| 710 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 711 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 712 | if (state->ws->focus_animation) |
| 713 | weston_view_animation_destroy(state->ws->focus_animation); |
| 714 | |
| 715 | state->ws->focus_animation = weston_fade_run( |
| 716 | state->ws->fsurf_front->view, |
| 717 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 718 | focus_animation_done, state->ws); |
| 719 | } |
| 720 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 721 | wl_list_remove(&state->link); |
| 722 | focus_state_destroy(state); |
| 723 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 727 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 728 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 729 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 730 | |
| 731 | state = malloc(sizeof *state); |
| 732 | if (state == NULL) |
| 733 | return NULL; |
| 734 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 735 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 736 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 737 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 738 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 739 | |
| 740 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 741 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 742 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 743 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 744 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 745 | |
| 746 | return state; |
| 747 | } |
| 748 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 749 | static struct focus_state * |
| 750 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 751 | { |
| 752 | struct workspace *ws = get_current_workspace(shell); |
| 753 | struct focus_state *state; |
| 754 | |
| 755 | wl_list_for_each(state, &ws->focus_list, link) |
| 756 | if (state->seat == seat) |
| 757 | break; |
| 758 | |
| 759 | if (&state->link == &ws->focus_list) |
| 760 | state = focus_state_create(seat, ws); |
| 761 | |
| 762 | return state; |
| 763 | } |
| 764 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 765 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 766 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 767 | { |
| 768 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 769 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 770 | |
| 771 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 772 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 773 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 774 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
| 778 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 779 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 780 | struct weston_seat *seat) |
| 781 | { |
| 782 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 783 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 784 | |
| 785 | wl_list_for_each(state, &ws->focus_list, link) { |
| 786 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 787 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 788 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 789 | return; |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | static void |
| 795 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 796 | struct weston_surface *surface) |
| 797 | { |
| 798 | struct focus_state *state; |
| 799 | |
| 800 | wl_list_for_each(state, &ws->focus_list, link) |
| 801 | if (state->keyboard_focus == surface) |
| 802 | state->keyboard_focus = NULL; |
| 803 | } |
| 804 | |
| 805 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 806 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 807 | struct weston_view *from, struct weston_view *to) |
| 808 | { |
| 809 | struct weston_output *output; |
| 810 | bool focus_surface_created = false; |
| 811 | |
| 812 | /* FIXME: Only support dim animation using two layers */ |
| 813 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 814 | return; |
| 815 | |
| 816 | output = get_default_output(shell->compositor); |
| 817 | if (ws->fsurf_front == NULL && (from || to)) { |
| 818 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 819 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 820 | ws->fsurf_front->view->alpha = 0.0; |
| 821 | ws->fsurf_back->view->alpha = 0.0; |
| 822 | focus_surface_created = true; |
| 823 | } else { |
| 824 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 825 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 826 | } |
| 827 | |
| 828 | if (ws->focus_animation) { |
| 829 | weston_view_animation_destroy(ws->focus_animation); |
| 830 | ws->focus_animation = NULL; |
| 831 | } |
| 832 | |
| 833 | if (to) |
| 834 | wl_list_insert(&to->layer_link, |
| 835 | &ws->fsurf_front->view->layer_link); |
| 836 | else if (from) |
| 837 | wl_list_insert(&ws->layer.view_list, |
| 838 | &ws->fsurf_front->view->layer_link); |
| 839 | |
| 840 | if (focus_surface_created) { |
| 841 | ws->focus_animation = weston_fade_run( |
| 842 | ws->fsurf_front->view, |
| 843 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 844 | focus_animation_done, ws); |
| 845 | } else if (from) { |
| 846 | wl_list_insert(&from->layer_link, |
| 847 | &ws->fsurf_back->view->layer_link); |
| 848 | ws->focus_animation = weston_stable_fade_run( |
| 849 | ws->fsurf_front->view, 0.0, |
| 850 | ws->fsurf_back->view, 0.6, |
| 851 | focus_animation_done, ws); |
| 852 | } else if (to) { |
| 853 | wl_list_insert(&ws->layer.view_list, |
| 854 | &ws->fsurf_back->view->layer_link); |
| 855 | ws->focus_animation = weston_stable_fade_run( |
| 856 | ws->fsurf_front->view, 0.0, |
| 857 | ws->fsurf_back->view, 0.6, |
| 858 | focus_animation_done, ws); |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 863 | workspace_destroy(struct workspace *ws) |
| 864 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 865 | struct focus_state *state, *next; |
| 866 | |
| 867 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 868 | focus_state_destroy(state); |
| 869 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 870 | if (ws->fsurf_front) |
| 871 | focus_surface_destroy(ws->fsurf_front); |
| 872 | if (ws->fsurf_back) |
| 873 | focus_surface_destroy(ws->fsurf_back); |
| 874 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 875 | free(ws); |
| 876 | } |
| 877 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 878 | static void |
| 879 | seat_destroyed(struct wl_listener *listener, void *data) |
| 880 | { |
| 881 | struct weston_seat *seat = data; |
| 882 | struct focus_state *state, *next; |
| 883 | struct workspace *ws = container_of(listener, |
| 884 | struct workspace, |
| 885 | seat_destroyed_listener); |
| 886 | |
| 887 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 888 | if (state->seat == seat) |
| 889 | wl_list_remove(&state->link); |
| 890 | } |
| 891 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 892 | static struct workspace * |
| 893 | workspace_create(void) |
| 894 | { |
| 895 | struct workspace *ws = malloc(sizeof *ws); |
| 896 | if (ws == NULL) |
| 897 | return NULL; |
| 898 | |
| 899 | weston_layer_init(&ws->layer, NULL); |
| 900 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 901 | wl_list_init(&ws->focus_list); |
| 902 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 903 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 904 | ws->fsurf_front = NULL; |
| 905 | ws->fsurf_back = NULL; |
| 906 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 907 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 908 | return ws; |
| 909 | } |
| 910 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 911 | static int |
| 912 | workspace_is_empty(struct workspace *ws) |
| 913 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 914 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 915 | } |
| 916 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 917 | static struct workspace * |
| 918 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 919 | { |
| 920 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 921 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 922 | pws += index; |
| 923 | return *pws; |
| 924 | } |
| 925 | |
| 926 | static struct workspace * |
| 927 | get_current_workspace(struct desktop_shell *shell) |
| 928 | { |
| 929 | return get_workspace(shell, shell->workspaces.current); |
| 930 | } |
| 931 | |
| 932 | static void |
| 933 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 934 | { |
| 935 | struct workspace *ws; |
| 936 | |
| 937 | ws = get_workspace(shell, index); |
| 938 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 939 | |
| 940 | shell->workspaces.current = index; |
| 941 | } |
| 942 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 943 | static unsigned int |
| 944 | get_output_height(struct weston_output *output) |
| 945 | { |
| 946 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 947 | } |
| 948 | |
| 949 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 950 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 951 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 952 | struct weston_transform *transform; |
| 953 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 954 | if (is_focus_view(view)) { |
| 955 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 956 | transform = &fsurf->workspace_transform; |
| 957 | } else { |
| 958 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 959 | transform = &shsurf->workspace_transform; |
| 960 | } |
| 961 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 962 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 963 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 964 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 965 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 966 | weston_matrix_init(&transform->matrix); |
| 967 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 968 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 969 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static void |
| 973 | workspace_translate_out(struct workspace *ws, double fraction) |
| 974 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 975 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 976 | unsigned int height; |
| 977 | double d; |
| 978 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 979 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 980 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 981 | d = height * fraction; |
| 982 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 983 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | |
| 987 | static void |
| 988 | workspace_translate_in(struct workspace *ws, double fraction) |
| 989 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 990 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 991 | unsigned int height; |
| 992 | double d; |
| 993 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 994 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 995 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 996 | |
| 997 | if (fraction > 0) |
| 998 | d = -(height - height * fraction); |
| 999 | else |
| 1000 | d = height + height * fraction; |
| 1001 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1002 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1007 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1008 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1009 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1010 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1011 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1012 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1013 | shell->workspaces.current, |
| 1014 | shell->workspaces.num); |
| 1015 | } |
| 1016 | |
| 1017 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1018 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1019 | unsigned int index, |
| 1020 | struct workspace *from, |
| 1021 | struct workspace *to) |
| 1022 | { |
| 1023 | shell->workspaces.current = index; |
| 1024 | |
| 1025 | shell->workspaces.anim_to = to; |
| 1026 | shell->workspaces.anim_from = from; |
| 1027 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1028 | shell->workspaces.anim_timestamp = 0; |
| 1029 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1030 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static void |
| 1034 | workspace_deactivate_transforms(struct workspace *ws) |
| 1035 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1036 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1037 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1038 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1039 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1040 | if (is_focus_view(view)) { |
| 1041 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1042 | transform = &fsurf->workspace_transform; |
| 1043 | } else { |
| 1044 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1045 | transform = &shsurf->workspace_transform; |
| 1046 | } |
| 1047 | |
| 1048 | if (!wl_list_empty(&transform->link)) { |
| 1049 | wl_list_remove(&transform->link); |
| 1050 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1051 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1052 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | static void |
| 1057 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1058 | struct workspace *from, |
| 1059 | struct workspace *to) |
| 1060 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1061 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1062 | |
| 1063 | wl_list_remove(&shell->workspaces.animation.link); |
| 1064 | workspace_deactivate_transforms(from); |
| 1065 | workspace_deactivate_transforms(to); |
| 1066 | shell->workspaces.anim_to = NULL; |
| 1067 | |
| 1068 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1069 | } |
| 1070 | |
| 1071 | static void |
| 1072 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1073 | struct weston_output *output, uint32_t msecs) |
| 1074 | { |
| 1075 | struct desktop_shell *shell = |
| 1076 | container_of(animation, struct desktop_shell, |
| 1077 | workspaces.animation); |
| 1078 | struct workspace *from = shell->workspaces.anim_from; |
| 1079 | struct workspace *to = shell->workspaces.anim_to; |
| 1080 | uint32_t t; |
| 1081 | double x, y; |
| 1082 | |
| 1083 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1084 | finish_workspace_change_animation(shell, from, to); |
| 1085 | return; |
| 1086 | } |
| 1087 | |
| 1088 | if (shell->workspaces.anim_timestamp == 0) { |
| 1089 | if (shell->workspaces.anim_current == 0.0) |
| 1090 | shell->workspaces.anim_timestamp = msecs; |
| 1091 | else |
| 1092 | shell->workspaces.anim_timestamp = |
| 1093 | msecs - |
| 1094 | /* Invers of movement function 'y' below. */ |
| 1095 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1096 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1097 | M_2_PI); |
| 1098 | } |
| 1099 | |
| 1100 | t = msecs - shell->workspaces.anim_timestamp; |
| 1101 | |
| 1102 | /* |
| 1103 | * x = [0, π/2] |
| 1104 | * y(x) = sin(x) |
| 1105 | */ |
| 1106 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1107 | y = sin(x); |
| 1108 | |
| 1109 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1110 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1111 | |
| 1112 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1113 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1114 | shell->workspaces.anim_current = y; |
| 1115 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1116 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1117 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1118 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1119 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | static void |
| 1123 | animate_workspace_change(struct desktop_shell *shell, |
| 1124 | unsigned int index, |
| 1125 | struct workspace *from, |
| 1126 | struct workspace *to) |
| 1127 | { |
| 1128 | struct weston_output *output; |
| 1129 | |
| 1130 | int dir; |
| 1131 | |
| 1132 | if (index > shell->workspaces.current) |
| 1133 | dir = -1; |
| 1134 | else |
| 1135 | dir = 1; |
| 1136 | |
| 1137 | shell->workspaces.current = index; |
| 1138 | |
| 1139 | shell->workspaces.anim_dir = dir; |
| 1140 | shell->workspaces.anim_from = from; |
| 1141 | shell->workspaces.anim_to = to; |
| 1142 | shell->workspaces.anim_current = 0.0; |
| 1143 | shell->workspaces.anim_timestamp = 0; |
| 1144 | |
| 1145 | output = container_of(shell->compositor->output_list.next, |
| 1146 | struct weston_output, link); |
| 1147 | wl_list_insert(&output->animation_list, |
| 1148 | &shell->workspaces.animation.link); |
| 1149 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1150 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1151 | |
| 1152 | workspace_translate_in(to, 0); |
| 1153 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1154 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1155 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1156 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1157 | } |
| 1158 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1159 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1160 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1161 | struct workspace *from, struct workspace *to) |
| 1162 | { |
| 1163 | shell->workspaces.current = index; |
| 1164 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1165 | wl_list_remove(&from->layer.link); |
| 1166 | } |
| 1167 | |
| 1168 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1169 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1170 | { |
| 1171 | struct workspace *from; |
| 1172 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1173 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1174 | |
| 1175 | if (index == shell->workspaces.current) |
| 1176 | return; |
| 1177 | |
| 1178 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1179 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1180 | return; |
| 1181 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1182 | from = get_current_workspace(shell); |
| 1183 | to = get_workspace(shell, index); |
| 1184 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1185 | if (shell->workspaces.anim_from == to && |
| 1186 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1187 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1188 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1189 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1190 | return; |
| 1191 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1192 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1193 | if (shell->workspaces.anim_to != NULL) |
| 1194 | finish_workspace_change_animation(shell, |
| 1195 | shell->workspaces.anim_from, |
| 1196 | shell->workspaces.anim_to); |
| 1197 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1198 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1199 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1200 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1201 | wl_list_for_each(state, &from->focus_list, link) |
| 1202 | if (state->keyboard_focus) |
| 1203 | animate_focus_change(shell, from, |
| 1204 | get_default_view(state->keyboard_focus), NULL); |
| 1205 | |
| 1206 | wl_list_for_each(state, &to->focus_list, link) |
| 1207 | if (state->keyboard_focus) |
| 1208 | animate_focus_change(shell, to, |
| 1209 | NULL, get_default_view(state->keyboard_focus)); |
| 1210 | } |
| 1211 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1212 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1213 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1214 | else |
| 1215 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1216 | |
| 1217 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1218 | } |
| 1219 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1220 | static bool |
| 1221 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1222 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1223 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1224 | struct wl_list *e; |
| 1225 | |
| 1226 | if (wl_list_empty(list)) |
| 1227 | return false; |
| 1228 | |
| 1229 | e = list->next; |
| 1230 | |
| 1231 | if (e->next != list) |
| 1232 | return false; |
| 1233 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1234 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1238 | move_view_to_workspace(struct desktop_shell *shell, |
| 1239 | struct weston_view *view, |
| 1240 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1241 | { |
| 1242 | struct workspace *from; |
| 1243 | struct workspace *to; |
| 1244 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1245 | struct weston_surface *focus; |
| 1246 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1247 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1248 | |
| 1249 | if (workspace == shell->workspaces.current) |
| 1250 | return; |
| 1251 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1252 | if (workspace >= shell->workspaces.num) |
| 1253 | workspace = shell->workspaces.num - 1; |
| 1254 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1255 | from = get_current_workspace(shell); |
| 1256 | to = get_workspace(shell, workspace); |
| 1257 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1258 | wl_list_remove(&view->layer_link); |
| 1259 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1260 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1261 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1262 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1263 | if (!seat->keyboard) |
| 1264 | continue; |
| 1265 | |
| 1266 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1267 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1268 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1269 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1270 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1271 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1275 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1276 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1277 | unsigned int index) |
| 1278 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1279 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1280 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1281 | struct shell_surface *shsurf; |
| 1282 | struct workspace *from; |
| 1283 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1284 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1285 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1286 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1287 | view = get_default_view(surface); |
| 1288 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1289 | index == shell->workspaces.current || |
| 1290 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1291 | return; |
| 1292 | |
| 1293 | from = get_current_workspace(shell); |
| 1294 | to = get_workspace(shell, index); |
| 1295 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1296 | wl_list_remove(&view->layer_link); |
| 1297 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1298 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1299 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1300 | drop_focus_state(shell, from, surface); |
| 1301 | |
| 1302 | if (shell->workspaces.anim_from == to && |
| 1303 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1304 | wl_list_remove(&to->layer.link); |
| 1305 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1306 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1307 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1308 | broadcast_current_workspace_state(shell); |
| 1309 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | if (shell->workspaces.anim_to != NULL) |
| 1314 | finish_workspace_change_animation(shell, |
| 1315 | shell->workspaces.anim_from, |
| 1316 | shell->workspaces.anim_to); |
| 1317 | |
| 1318 | if (workspace_is_empty(from) && |
| 1319 | workspace_has_only(to, surface)) |
| 1320 | update_workspace(shell, index, from, to); |
| 1321 | else { |
| 1322 | shsurf = get_shell_surface(surface); |
| 1323 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 1324 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1325 | &shsurf->workspace_transform.link); |
| 1326 | |
| 1327 | animate_workspace_change(shell, index, from, to); |
| 1328 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1329 | |
| 1330 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1331 | |
| 1332 | state = ensure_focus_state(shell, seat); |
| 1333 | if (state != NULL) |
| 1334 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | static void |
| 1338 | workspace_manager_move_surface(struct wl_client *client, |
| 1339 | struct wl_resource *resource, |
| 1340 | struct wl_resource *surface_resource, |
| 1341 | uint32_t workspace) |
| 1342 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1343 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1344 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1345 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1346 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1347 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1348 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1349 | main_surface = weston_surface_get_main_surface(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1350 | view = get_default_view(main_surface); |
| 1351 | if (!view) |
| 1352 | return; |
| 1353 | move_view_to_workspace(shell, view, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1357 | workspace_manager_move_surface, |
| 1358 | }; |
| 1359 | |
| 1360 | static void |
| 1361 | unbind_resource(struct wl_resource *resource) |
| 1362 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1363 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | static void |
| 1367 | bind_workspace_manager(struct wl_client *client, |
| 1368 | void *data, uint32_t version, uint32_t id) |
| 1369 | { |
| 1370 | struct desktop_shell *shell = data; |
| 1371 | struct wl_resource *resource; |
| 1372 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1373 | resource = wl_resource_create(client, |
| 1374 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1375 | |
| 1376 | if (resource == NULL) { |
| 1377 | weston_log("couldn't add workspace manager object"); |
| 1378 | return; |
| 1379 | } |
| 1380 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1381 | wl_resource_set_implementation(resource, |
| 1382 | &workspace_manager_implementation, |
| 1383 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1384 | wl_list_insert(&shell->workspaces.client_list, |
| 1385 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1386 | |
| 1387 | workspace_manager_send_state(resource, |
| 1388 | shell->workspaces.current, |
| 1389 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1390 | } |
| 1391 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1392 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1393 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1394 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1395 | { |
| 1396 | } |
| 1397 | |
| 1398 | static void |
| 1399 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1400 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1401 | struct weston_touch_move_grab *move = |
| 1402 | (struct weston_touch_move_grab *) container_of( |
| 1403 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1404 | |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1405 | if (grab->touch->seat->num_tp == 0) { |
| 1406 | shell_touch_grab_end(&move->base); |
| 1407 | free(move); |
| 1408 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | static void |
| 1412 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1413 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1414 | { |
| 1415 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1416 | struct shell_surface *shsurf = move->base.shsurf; |
| 1417 | struct weston_surface *es; |
| 1418 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1419 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1420 | |
| 1421 | if (!shsurf) |
| 1422 | return; |
| 1423 | |
| 1424 | es = shsurf->surface; |
| 1425 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1426 | weston_view_configure(shsurf->view, dx, dy, |
| 1427 | shsurf->view->geometry.width, |
| 1428 | shsurf->view->geometry.height); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1429 | |
| 1430 | weston_compositor_schedule_repaint(es->compositor); |
| 1431 | } |
| 1432 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1433 | static void |
| 1434 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1435 | { |
| 1436 | struct weston_touch_move_grab *move = |
| 1437 | (struct weston_touch_move_grab *) container_of( |
| 1438 | grab, struct shell_touch_grab, grab); |
| 1439 | |
| 1440 | shell_touch_grab_end(&move->base); |
| 1441 | free(move); |
| 1442 | } |
| 1443 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1444 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1445 | touch_move_grab_down, |
| 1446 | touch_move_grab_up, |
| 1447 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1448 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1449 | }; |
| 1450 | |
| 1451 | static int |
| 1452 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1453 | { |
| 1454 | struct weston_touch_move_grab *move; |
| 1455 | |
| 1456 | if (!shsurf) |
| 1457 | return -1; |
| 1458 | |
| 1459 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1460 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1461 | if (shsurf->grabbed) |
| 1462 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1463 | |
| 1464 | move = malloc(sizeof *move); |
| 1465 | if (!move) |
| 1466 | return -1; |
| 1467 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1468 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1469 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1470 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1471 | seat->touch->grab_y; |
| 1472 | |
| 1473 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1474 | seat->touch); |
| 1475 | |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
| 1479 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1480 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1481 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1485 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1486 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1487 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1488 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1489 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1490 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1491 | int dx, dy; |
| 1492 | |
| 1493 | weston_pointer_move(pointer, x, y); |
| 1494 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1495 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1496 | |
| 1497 | if (!shsurf) |
| 1498 | return; |
| 1499 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1500 | weston_view_configure(shsurf->view, dx, dy, |
| 1501 | shsurf->view->geometry.width, |
| 1502 | shsurf->view->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1503 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1504 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1508 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1509 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1510 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1511 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1512 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1513 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1514 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1515 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1516 | if (pointer->button_count == 0 && |
| 1517 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1518 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1519 | free(grab); |
| 1520 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1521 | } |
| 1522 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1523 | static void |
| 1524 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1525 | { |
| 1526 | struct shell_grab *shell_grab = |
| 1527 | container_of(grab, struct shell_grab, grab); |
| 1528 | |
| 1529 | shell_grab_end(shell_grab); |
| 1530 | free(grab); |
| 1531 | } |
| 1532 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1533 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1534 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1535 | move_grab_motion, |
| 1536 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1537 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1538 | }; |
| 1539 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1540 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1541 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1542 | { |
| 1543 | struct weston_move_grab *move; |
| 1544 | |
| 1545 | if (!shsurf) |
| 1546 | return -1; |
| 1547 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1548 | if (shsurf->grabbed) |
| 1549 | return 0; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1550 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1551 | return 0; |
| 1552 | |
| 1553 | move = malloc(sizeof *move); |
| 1554 | if (!move) |
| 1555 | return -1; |
| 1556 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1557 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1558 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1559 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1560 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1561 | |
| 1562 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1563 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1564 | |
| 1565 | return 0; |
| 1566 | } |
| 1567 | |
| 1568 | static void |
| 1569 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1570 | struct wl_resource *seat_resource, uint32_t serial) |
| 1571 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1572 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1573 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1574 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1575 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1576 | if (seat->pointer && |
| 1577 | seat->pointer->button_count > 0 && |
| 1578 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1579 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1580 | if ((surface == shsurf->surface) && |
| 1581 | (surface_move(shsurf, seat) < 0)) |
| 1582 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1583 | } else if (seat->touch && |
| 1584 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1585 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1586 | if ((surface == shsurf->surface) && |
| 1587 | (surface_touch_move(shsurf, seat) < 0)) |
| 1588 | wl_resource_post_no_memory(resource); |
| 1589 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | struct weston_resize_grab { |
| 1593 | struct shell_grab base; |
| 1594 | uint32_t edges; |
| 1595 | int32_t width, height; |
| 1596 | }; |
| 1597 | |
| 1598 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1599 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1600 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1601 | { |
| 1602 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1603 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1604 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1605 | int32_t width, height; |
| 1606 | wl_fixed_t from_x, from_y; |
| 1607 | wl_fixed_t to_x, to_y; |
| 1608 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1609 | weston_pointer_move(pointer, x, y); |
| 1610 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1611 | if (!shsurf) |
| 1612 | return; |
| 1613 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1614 | weston_view_from_global_fixed(shsurf->view, |
| 1615 | pointer->grab_x, pointer->grab_y, |
| 1616 | &from_x, &from_y); |
| 1617 | weston_view_from_global_fixed(shsurf->view, |
| 1618 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1619 | |
| 1620 | width = resize->width; |
| 1621 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1622 | width += wl_fixed_to_int(from_x - to_x); |
| 1623 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1624 | width += wl_fixed_to_int(to_x - from_x); |
| 1625 | } |
| 1626 | |
| 1627 | height = resize->height; |
| 1628 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1629 | height += wl_fixed_to_int(from_y - to_y); |
| 1630 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1631 | height += wl_fixed_to_int(to_y - from_y); |
| 1632 | } |
| 1633 | |
| 1634 | shsurf->client->send_configure(shsurf->surface, |
| 1635 | resize->edges, width, height); |
| 1636 | } |
| 1637 | |
| 1638 | static void |
| 1639 | send_configure(struct weston_surface *surface, |
| 1640 | uint32_t edges, int32_t width, int32_t height) |
| 1641 | { |
| 1642 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1643 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1644 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1645 | edges, width, height); |
| 1646 | } |
| 1647 | |
| 1648 | static const struct weston_shell_client shell_client = { |
| 1649 | send_configure |
| 1650 | }; |
| 1651 | |
| 1652 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1653 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1654 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1655 | { |
| 1656 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1657 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1658 | enum wl_pointer_button_state state = state_w; |
| 1659 | |
| 1660 | if (pointer->button_count == 0 && |
| 1661 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1662 | shell_grab_end(&resize->base); |
| 1663 | free(grab); |
| 1664 | } |
| 1665 | } |
| 1666 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1667 | static void |
| 1668 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1669 | { |
| 1670 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1671 | |
| 1672 | shell_grab_end(&resize->base); |
| 1673 | free(grab); |
| 1674 | } |
| 1675 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1676 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1677 | noop_grab_focus, |
| 1678 | resize_grab_motion, |
| 1679 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1680 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1681 | }; |
| 1682 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1683 | /* |
| 1684 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1685 | * in the surface coordinates system. */ |
| 1686 | static void |
| 1687 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1688 | int32_t *y, int32_t *w, int32_t *h) { |
| 1689 | pixman_region32_t region; |
| 1690 | pixman_box32_t *box; |
| 1691 | struct weston_subsurface *subsurface; |
| 1692 | |
| 1693 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1694 | surface->width, |
| 1695 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1696 | |
| 1697 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1698 | pixman_region32_union_rect(®ion, ®ion, |
| 1699 | subsurface->position.x, |
| 1700 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1701 | subsurface->surface->width, |
| 1702 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | box = pixman_region32_extents(®ion); |
| 1706 | if (x) |
| 1707 | *x = box->x1; |
| 1708 | if (y) |
| 1709 | *y = box->y1; |
| 1710 | if (w) |
| 1711 | *w = box->x2 - box->x1; |
| 1712 | if (h) |
| 1713 | *h = box->y2 - box->y1; |
| 1714 | |
| 1715 | pixman_region32_fini(®ion); |
| 1716 | } |
| 1717 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1718 | static int |
| 1719 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1720 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1721 | { |
| 1722 | struct weston_resize_grab *resize; |
| 1723 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1724 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1725 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1726 | return 0; |
| 1727 | |
| 1728 | if (edges == 0 || edges > 15 || |
| 1729 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1730 | return 0; |
| 1731 | |
| 1732 | resize = malloc(sizeof *resize); |
| 1733 | if (!resize) |
| 1734 | return -1; |
| 1735 | |
| 1736 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1737 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1738 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1739 | |
| 1740 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1741 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1742 | |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
| 1746 | static void |
| 1747 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1748 | struct wl_resource *seat_resource, uint32_t serial, |
| 1749 | uint32_t edges) |
| 1750 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1751 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1752 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1753 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1754 | |
| 1755 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1756 | return; |
| 1757 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1758 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1759 | if (seat->pointer->button_count == 0 || |
| 1760 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1761 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1762 | return; |
| 1763 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1764 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1765 | wl_resource_post_no_memory(resource); |
| 1766 | } |
| 1767 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1768 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1769 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1770 | |
| 1771 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1772 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1773 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1774 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1775 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1776 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1777 | wl_fixed_t sx, sy; |
| 1778 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1779 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1780 | pointer->x, pointer->y, |
| 1781 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1782 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1783 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1784 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1788 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1789 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1790 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1791 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1792 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1793 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1794 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1795 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1796 | uint32_t time, uint32_t button, uint32_t state) |
| 1797 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1798 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1799 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1800 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1801 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1802 | if (shsurf && button == BTN_LEFT && state) { |
| 1803 | activate(shsurf->shell, shsurf->surface, seat); |
| 1804 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1805 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1806 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1807 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1808 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1809 | } |
| 1810 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1811 | static void |
| 1812 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1813 | { |
| 1814 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1815 | |
| 1816 | shell_grab_end(grab); |
| 1817 | free(grab); |
| 1818 | } |
| 1819 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1820 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1821 | busy_cursor_grab_focus, |
| 1822 | busy_cursor_grab_motion, |
| 1823 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1824 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1825 | }; |
| 1826 | |
| 1827 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1828 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1829 | { |
| 1830 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1831 | |
| 1832 | grab = malloc(sizeof *grab); |
| 1833 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1834 | return; |
| 1835 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1836 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1837 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1838 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1839 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1840 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1841 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1842 | { |
| 1843 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1844 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1845 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1846 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1847 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1848 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1849 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1850 | } |
| 1851 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1852 | static void |
| 1853 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1854 | { |
| 1855 | if (!shsurf || !shsurf->ping_timer) |
| 1856 | return; |
| 1857 | |
| 1858 | if (shsurf->ping_timer->source) |
| 1859 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1860 | |
| 1861 | free(shsurf->ping_timer); |
| 1862 | shsurf->ping_timer = NULL; |
| 1863 | } |
| 1864 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1865 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1866 | ping_timeout_handler(void *data) |
| 1867 | { |
| 1868 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1869 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1870 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1871 | /* Client is not responding */ |
| 1872 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1873 | |
| 1874 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1875 | if (seat->pointer->focus && |
| 1876 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1877 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1878 | |
| 1879 | return 1; |
| 1880 | } |
| 1881 | |
| 1882 | static void |
| 1883 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1884 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1885 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1886 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1887 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1888 | |
| 1889 | if (!shsurf) |
| 1890 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1891 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1892 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1893 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1894 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1895 | return; |
| 1896 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1897 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1898 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1899 | if (!shsurf->ping_timer) |
| 1900 | return; |
| 1901 | |
| 1902 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1903 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1904 | shsurf->ping_timer->source = |
| 1905 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1906 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1907 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1908 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1913 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1914 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1915 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1916 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1917 | struct weston_compositor *compositor; |
| 1918 | struct shell_surface *shsurf; |
| 1919 | uint32_t serial; |
| 1920 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1921 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1922 | return; |
| 1923 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1924 | compositor = view->surface->compositor; |
| 1925 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1926 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1927 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1928 | set_busy_cursor(shsurf, pointer); |
| 1929 | } else { |
| 1930 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1931 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1936 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1937 | { |
| 1938 | struct wl_listener *listener; |
| 1939 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1940 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1941 | return; |
| 1942 | |
| 1943 | listener = malloc(sizeof *listener); |
| 1944 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1945 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1949 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1950 | uint32_t serial) |
| 1951 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1952 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1953 | struct weston_seat *seat; |
| 1954 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1955 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1956 | if (shsurf->ping_timer == NULL) |
| 1957 | /* Just ignore unsolicited pong. */ |
| 1958 | return; |
| 1959 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1960 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1961 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1962 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1963 | if(seat->pointer) |
| 1964 | end_busy_cursor(shsurf, seat->pointer); |
| 1965 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1966 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1967 | } |
| 1968 | } |
| 1969 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1970 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1971 | set_title(struct shell_surface *shsurf, const char *title) |
| 1972 | { |
| 1973 | free(shsurf->title); |
| 1974 | shsurf->title = strdup(title); |
| 1975 | } |
| 1976 | |
| 1977 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1978 | shell_surface_set_title(struct wl_client *client, |
| 1979 | struct wl_resource *resource, const char *title) |
| 1980 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1981 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1982 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1983 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | static void |
| 1987 | shell_surface_set_class(struct wl_client *client, |
| 1988 | struct wl_resource *resource, const char *class) |
| 1989 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1990 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1991 | |
| 1992 | free(shsurf->class); |
| 1993 | shsurf->class = strdup(class); |
| 1994 | } |
| 1995 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1996 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1997 | restore_output_mode(struct weston_output *output) |
| 1998 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1999 | if (output->current_mode != output->original_mode || |
| 2000 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2001 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2002 | output->original_mode, |
| 2003 | output->original_scale, |
| 2004 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | static void |
| 2008 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2009 | { |
| 2010 | struct weston_output *output; |
| 2011 | |
| 2012 | wl_list_for_each(output, &compositor->output_list, link) |
| 2013 | restore_output_mode(output); |
| 2014 | } |
| 2015 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2016 | static int |
| 2017 | get_output_panel_height(struct desktop_shell *shell, |
| 2018 | struct weston_output *output) |
| 2019 | { |
| 2020 | struct weston_view *view; |
| 2021 | int panel_height = 0; |
| 2022 | |
| 2023 | if (!output) |
| 2024 | return 0; |
| 2025 | |
| 2026 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2027 | if (view->surface->output == output) { |
| 2028 | panel_height = view->geometry.height; |
| 2029 | break; |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | return panel_height; |
| 2034 | } |
| 2035 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2036 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2037 | set_toplevel(struct shell_surface *shsurf) |
| 2038 | { |
| 2039 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
| 2040 | } |
| 2041 | |
| 2042 | static void |
| 2043 | shell_surface_set_toplevel(struct wl_client *client, |
| 2044 | struct wl_resource *resource) |
| 2045 | { |
| 2046 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2047 | |
| 2048 | set_toplevel(surface); |
| 2049 | } |
| 2050 | |
| 2051 | static void |
| 2052 | set_transient(struct shell_surface *shsurf, |
| 2053 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2054 | { |
| 2055 | /* assign to parents output */ |
| 2056 | shsurf->parent = parent; |
| 2057 | shsurf->transient.x = x; |
| 2058 | shsurf->transient.y = y; |
| 2059 | shsurf->transient.flags = flags; |
| 2060 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 2061 | } |
| 2062 | |
| 2063 | static void |
| 2064 | shell_surface_set_transient(struct wl_client *client, |
| 2065 | struct wl_resource *resource, |
| 2066 | struct wl_resource *parent_resource, |
| 2067 | int x, int y, uint32_t flags) |
| 2068 | { |
| 2069 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2070 | struct weston_surface *parent = |
| 2071 | wl_resource_get_user_data(parent_resource); |
| 2072 | |
| 2073 | set_transient(shsurf, parent, x, y, flags); |
| 2074 | } |
| 2075 | |
| 2076 | static void |
| 2077 | set_fullscreen(struct shell_surface *shsurf, |
| 2078 | uint32_t method, |
| 2079 | uint32_t framerate, |
| 2080 | struct weston_output *output) |
| 2081 | { |
| 2082 | struct weston_surface *es = shsurf->surface; |
| 2083 | |
| 2084 | if (output) |
| 2085 | shsurf->output = output; |
| 2086 | else if (es->output) |
| 2087 | shsurf->output = es->output; |
| 2088 | else |
| 2089 | shsurf->output = get_default_output(es->compositor); |
| 2090 | |
| 2091 | shsurf->fullscreen_output = shsurf->output; |
| 2092 | shsurf->fullscreen.type = method; |
| 2093 | shsurf->fullscreen.framerate = framerate; |
| 2094 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
| 2095 | |
| 2096 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2097 | shsurf->output->width, |
| 2098 | shsurf->output->height); |
| 2099 | } |
| 2100 | |
| 2101 | static void |
| 2102 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2103 | { |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2104 | struct workspace *ws; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2105 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2106 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2107 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2108 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2109 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2110 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2111 | shsurf->fullscreen.framerate = 0; |
| 2112 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2113 | wl_list_init(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2114 | if (shsurf->fullscreen.black_view) |
| 2115 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2116 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2117 | shsurf->fullscreen_output = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2118 | weston_view_set_position(shsurf->view, |
| 2119 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2120 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2121 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2122 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2123 | shsurf->saved_rotation_valid = false; |
| 2124 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2125 | |
| 2126 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2127 | wl_list_remove(&shsurf->view->layer_link); |
| 2128 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2129 | } |
| 2130 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2131 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2132 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2133 | struct wl_resource *resource, |
| 2134 | uint32_t method, |
| 2135 | uint32_t framerate, |
| 2136 | struct wl_resource *output_resource) |
| 2137 | { |
| 2138 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2139 | struct weston_output *output; |
| 2140 | |
| 2141 | if (output_resource) |
| 2142 | output = wl_resource_get_user_data(output_resource); |
| 2143 | else |
| 2144 | output = NULL; |
| 2145 | |
| 2146 | set_fullscreen(shsurf, method, framerate, output); |
| 2147 | } |
| 2148 | |
| 2149 | static void |
| 2150 | set_popup(struct shell_surface *shsurf, |
| 2151 | struct weston_surface *parent, |
| 2152 | struct weston_seat *seat, |
| 2153 | uint32_t serial, |
| 2154 | int32_t x, |
| 2155 | int32_t y) |
| 2156 | { |
| 2157 | shsurf->type = SHELL_SURFACE_POPUP; |
| 2158 | shsurf->parent = parent; |
| 2159 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2160 | shsurf->popup.serial = serial; |
| 2161 | shsurf->popup.x = x; |
| 2162 | shsurf->popup.y = y; |
| 2163 | } |
| 2164 | |
| 2165 | static void |
| 2166 | shell_surface_set_popup(struct wl_client *client, |
| 2167 | struct wl_resource *resource, |
| 2168 | struct wl_resource *seat_resource, |
| 2169 | uint32_t serial, |
| 2170 | struct wl_resource *parent_resource, |
| 2171 | int32_t x, int32_t y, uint32_t flags) |
| 2172 | { |
| 2173 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2174 | |
| 2175 | set_popup(shsurf, |
| 2176 | wl_resource_get_user_data(parent_resource), |
| 2177 | wl_resource_get_user_data(seat_resource), |
| 2178 | serial, x, y); |
| 2179 | } |
| 2180 | |
| 2181 | static void |
| 2182 | set_maximized(struct shell_surface *shsurf, |
| 2183 | struct weston_output *output) |
| 2184 | { |
| 2185 | struct desktop_shell *shell; |
| 2186 | uint32_t edges = 0, panel_height = 0; |
| 2187 | struct weston_surface *es = shsurf->surface; |
| 2188 | |
| 2189 | /* get the default output, if the client set it as NULL |
| 2190 | check whether the ouput is available */ |
| 2191 | if (output) |
| 2192 | shsurf->output = output; |
| 2193 | else if (es->output) |
| 2194 | shsurf->output = es->output; |
| 2195 | else |
| 2196 | shsurf->output = get_default_output(es->compositor); |
| 2197 | |
| 2198 | shell = shell_surface_get_shell(shsurf); |
| 2199 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2200 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2201 | |
| 2202 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2203 | shsurf->output->width, |
| 2204 | shsurf->output->height - panel_height); |
| 2205 | |
| 2206 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
| 2207 | } |
| 2208 | |
| 2209 | static void |
| 2210 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2211 | { |
| 2212 | struct workspace *ws; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2213 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2214 | /* undo all maximized things here */ |
| 2215 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2216 | weston_view_set_position(shsurf->view, |
| 2217 | shsurf->saved_x, |
| 2218 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2219 | |
| 2220 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2221 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2222 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2223 | shsurf->saved_rotation_valid = false; |
| 2224 | } |
| 2225 | |
| 2226 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2227 | wl_list_remove(&shsurf->view->layer_link); |
| 2228 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2229 | } |
| 2230 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2231 | static void |
| 2232 | shell_surface_set_maximized(struct wl_client *client, |
| 2233 | struct wl_resource *resource, |
| 2234 | struct wl_resource *output_resource) |
| 2235 | { |
| 2236 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2237 | struct weston_output *output; |
| 2238 | |
| 2239 | if (output_resource) |
| 2240 | output = wl_resource_get_user_data(output_resource); |
| 2241 | else |
| 2242 | output = NULL; |
| 2243 | |
| 2244 | set_maximized(shsurf, output); |
| 2245 | } |
| 2246 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2247 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2248 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2249 | { |
| 2250 | switch (surface->type) { |
| 2251 | case SHELL_SURFACE_FULLSCREEN: |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2252 | unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2253 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2254 | case SHELL_SURFACE_MAXIMIZED: |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2255 | unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2256 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2257 | case SHELL_SURFACE_NONE: |
| 2258 | case SHELL_SURFACE_TOPLEVEL: |
| 2259 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2260 | case SHELL_SURFACE_POPUP: |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2261 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2262 | default: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2263 | break; |
| 2264 | } |
| 2265 | |
| 2266 | surface->type = SHELL_SURFACE_NONE; |
| 2267 | return 0; |
| 2268 | } |
| 2269 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2270 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2271 | set_surface_type(struct shell_surface *shsurf) |
| 2272 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2273 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2274 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2275 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2276 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2277 | |
| 2278 | shsurf->type = shsurf->next_type; |
| 2279 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 2280 | |
| 2281 | switch (shsurf->type) { |
| 2282 | case SHELL_SURFACE_TOPLEVEL: |
| 2283 | break; |
| 2284 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2285 | if (pev) |
| 2286 | weston_view_set_position(shsurf->view, |
| 2287 | pev->geometry.x + shsurf->transient.x, |
| 2288 | pev->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2289 | break; |
| 2290 | |
| 2291 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2292 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2293 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2294 | shsurf->saved_y = shsurf->view->geometry.y; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2295 | shsurf->saved_position_valid = true; |
| 2296 | |
| 2297 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2298 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2299 | wl_list_init(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2300 | weston_view_geometry_dirty(shsurf->view); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2301 | shsurf->saved_rotation_valid = true; |
| 2302 | } |
| 2303 | break; |
| 2304 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2305 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2306 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2307 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2308 | break; |
| 2309 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2310 | case SHELL_SURFACE_POPUP: |
| 2311 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2312 | default: |
| 2313 | break; |
| 2314 | } |
| 2315 | } |
| 2316 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2317 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2318 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2319 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2320 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2321 | } |
| 2322 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2323 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2324 | 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] | 2325 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2326 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2327 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2328 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2329 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2330 | { |
| 2331 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2332 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2333 | |
| 2334 | surface = weston_surface_create(ec); |
| 2335 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2336 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2337 | return NULL; |
| 2338 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2339 | view = weston_view_create(surface); |
| 2340 | if (surface == NULL) { |
| 2341 | weston_log("no memory\n"); |
| 2342 | weston_surface_destroy(surface); |
| 2343 | return NULL; |
| 2344 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2345 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2346 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2347 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2348 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2349 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2350 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2351 | pixman_region32_fini(&surface->input); |
| 2352 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2353 | surface->width = w; |
| 2354 | surface->height = h; |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2355 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2356 | weston_view_configure(view, x, y, w, h); |
| 2357 | |
| 2358 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | /* Create black surface and append it to the associated fullscreen surface. |
| 2362 | * Handle size dismatch and positioning according to the method. */ |
| 2363 | static void |
| 2364 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2365 | { |
| 2366 | struct weston_output *output = shsurf->fullscreen_output; |
| 2367 | struct weston_surface *surface = shsurf->surface; |
| 2368 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2369 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2370 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2371 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2372 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2373 | restore_output_mode(output); |
| 2374 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2375 | if (!shsurf->fullscreen.black_view) |
| 2376 | shsurf->fullscreen.black_view = |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2377 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2378 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2379 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2380 | output->width, |
| 2381 | output->height); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2382 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2383 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2384 | wl_list_insert(&shsurf->view->layer_link, |
| 2385 | &shsurf->fullscreen.black_view->layer_link); |
| 2386 | shsurf->fullscreen.black_view->surface->output = output; |
| 2387 | shsurf->fullscreen.black_view->output = output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2388 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2389 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2390 | &surf_width, &surf_height); |
| 2391 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2392 | switch (shsurf->fullscreen.type) { |
| 2393 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2394 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2395 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2396 | break; |
| 2397 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2398 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2399 | if (output->width == surf_width && |
| 2400 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2401 | weston_view_set_position(shsurf->view, |
| 2402 | output->x - surf_x, |
| 2403 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2404 | break; |
| 2405 | } |
| 2406 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2407 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2408 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2409 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2410 | output_aspect = (float) output->width / |
| 2411 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2412 | /* XXX: Use surf_width and surf_height here? */ |
| 2413 | surface_aspect = (float) surface->width / |
| 2414 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2415 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2416 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2417 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2418 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2419 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2420 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2421 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2422 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2423 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2424 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2425 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2426 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2427 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2428 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2429 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2430 | break; |
| 2431 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2432 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2433 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2434 | surf_width * surface->buffer_viewport.scale, |
| 2435 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2436 | shsurf->fullscreen.framerate}; |
| 2437 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2438 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2439 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2440 | weston_view_set_position(shsurf->view, |
| 2441 | output->x - surf_x, |
| 2442 | output->y - surf_y); |
| 2443 | weston_view_configure(shsurf->fullscreen.black_view, |
| 2444 | output->x - surf_x, |
| 2445 | output->y - surf_y, |
| 2446 | output->width, |
| 2447 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2448 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2449 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2450 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2451 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2452 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2453 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2454 | break; |
| 2455 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2456 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2457 | break; |
| 2458 | default: |
| 2459 | break; |
| 2460 | } |
| 2461 | } |
| 2462 | |
| 2463 | /* make the fullscreen and black surface at the top */ |
| 2464 | static void |
| 2465 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 2466 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2467 | struct weston_output *output = shsurf->fullscreen_output; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2468 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2469 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2470 | wl_list_remove(&shsurf->view->layer_link); |
| 2471 | wl_list_insert(&shell->fullscreen_layer.view_list, |
| 2472 | &shsurf->view->layer_link); |
| 2473 | weston_surface_damage(shsurf->surface); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2474 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2475 | if (!shsurf->fullscreen.black_view) |
| 2476 | shsurf->fullscreen.black_view = |
| 2477 | create_black_surface(shsurf->surface->compositor, |
| 2478 | shsurf->surface, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2479 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2480 | output->width, |
| 2481 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2482 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2483 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2484 | wl_list_insert(&shsurf->view->layer_link, |
| 2485 | &shsurf->fullscreen.black_view->layer_link); |
| 2486 | weston_surface_damage(shsurf->fullscreen.black_view->surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2487 | } |
| 2488 | |
| 2489 | static void |
| 2490 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2491 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2492 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2493 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2494 | } |
| 2495 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2496 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2497 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2498 | { |
| 2499 | /* XXX: using the same fields for transient type */ |
| 2500 | shsurf->transient.x = x; |
| 2501 | shsurf->transient.y = y; |
| 2502 | shsurf->transient.flags = flags; |
| 2503 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2504 | } |
| 2505 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2506 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2507 | |
| 2508 | static void |
| 2509 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2510 | { |
| 2511 | struct shell_seat *shseat = |
| 2512 | container_of(listener, |
| 2513 | struct shell_seat, seat_destroy_listener); |
| 2514 | struct shell_surface *shsurf, *prev = NULL; |
| 2515 | |
| 2516 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2517 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2518 | shseat->popup_grab.client = NULL; |
| 2519 | |
| 2520 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2521 | shsurf->popup.shseat = NULL; |
| 2522 | if (prev) { |
| 2523 | wl_list_init(&prev->popup.grab_link); |
| 2524 | } |
| 2525 | prev = shsurf; |
| 2526 | } |
| 2527 | wl_list_init(&prev->popup.grab_link); |
| 2528 | } |
| 2529 | |
| 2530 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2531 | free(shseat); |
| 2532 | } |
| 2533 | |
| 2534 | static struct shell_seat * |
| 2535 | create_shell_seat(struct weston_seat *seat) |
| 2536 | { |
| 2537 | struct shell_seat *shseat; |
| 2538 | |
| 2539 | shseat = calloc(1, sizeof *shseat); |
| 2540 | if (!shseat) { |
| 2541 | weston_log("no memory to allocate shell seat\n"); |
| 2542 | return NULL; |
| 2543 | } |
| 2544 | |
| 2545 | shseat->seat = seat; |
| 2546 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2547 | |
| 2548 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2549 | wl_signal_add(&seat->destroy_signal, |
| 2550 | &shseat->seat_destroy_listener); |
| 2551 | |
| 2552 | return shseat; |
| 2553 | } |
| 2554 | |
| 2555 | static struct shell_seat * |
| 2556 | get_shell_seat(struct weston_seat *seat) |
| 2557 | { |
| 2558 | struct wl_listener *listener; |
| 2559 | |
| 2560 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2561 | if (listener == NULL) |
| 2562 | return create_shell_seat(seat); |
| 2563 | |
| 2564 | return container_of(listener, |
| 2565 | struct shell_seat, seat_destroy_listener); |
| 2566 | } |
| 2567 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2568 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2569 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2570 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2571 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2572 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2573 | struct shell_seat *shseat = |
| 2574 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2575 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2576 | wl_fixed_t sx, sy; |
| 2577 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2578 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2579 | pointer->x, pointer->y, |
| 2580 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2581 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2582 | if (view && view->surface->resource && |
| 2583 | wl_resource_get_client(view->surface->resource) == client) { |
| 2584 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2585 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2586 | weston_pointer_set_focus(pointer, NULL, |
| 2587 | wl_fixed_from_int(0), |
| 2588 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2593 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2594 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2595 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2596 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2597 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2598 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2599 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2600 | weston_pointer_move(pointer, x, y); |
| 2601 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2602 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2603 | weston_view_from_global_fixed(pointer->focus, |
| 2604 | pointer->x, pointer->y, |
| 2605 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2606 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2607 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2611 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2612 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2613 | { |
| 2614 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2615 | struct shell_seat *shseat = |
| 2616 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2617 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2618 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2619 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2620 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2621 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2622 | resource_list = &grab->pointer->focus_resource_list; |
| 2623 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2624 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2625 | wl_resource_for_each(resource, resource_list) { |
| 2626 | wl_pointer_send_button(resource, serial, |
| 2627 | time, button, state); |
| 2628 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2629 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2630 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2631 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2632 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2633 | } |
| 2634 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2635 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2636 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2637 | } |
| 2638 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2639 | static void |
| 2640 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2641 | { |
| 2642 | popup_grab_end(grab->pointer); |
| 2643 | } |
| 2644 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2645 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2646 | popup_grab_focus, |
| 2647 | popup_grab_motion, |
| 2648 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2649 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2650 | }; |
| 2651 | |
| 2652 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2653 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2654 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2655 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2656 | struct shell_seat *shseat = |
| 2657 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2658 | struct shell_surface *shsurf; |
| 2659 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2660 | |
| 2661 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2662 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2663 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2664 | shseat->popup_grab.grab.interface = NULL; |
| 2665 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2666 | /* Send the popup_done event to all the popups open */ |
| 2667 | 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] | 2668 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2669 | shsurf->popup.shseat = NULL; |
| 2670 | if (prev) { |
| 2671 | wl_list_init(&prev->popup.grab_link); |
| 2672 | } |
| 2673 | prev = shsurf; |
| 2674 | } |
| 2675 | wl_list_init(&prev->popup.grab_link); |
| 2676 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2677 | } |
| 2678 | } |
| 2679 | |
| 2680 | static void |
| 2681 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2682 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2683 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2684 | |
| 2685 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2686 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2687 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2688 | /* We must make sure here that this popup was opened after |
| 2689 | * a mouse press, and not just by moving around with other |
| 2690 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2691 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2692 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2693 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2694 | 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] | 2695 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2696 | } else { |
| 2697 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2698 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | static void |
| 2702 | remove_popup_grab(struct shell_surface *shsurf) |
| 2703 | { |
| 2704 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2705 | |
| 2706 | wl_list_remove(&shsurf->popup.grab_link); |
| 2707 | wl_list_init(&shsurf->popup.grab_link); |
| 2708 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2709 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2710 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2715 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2716 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2717 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2718 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2719 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2720 | shsurf->surface->output = parent_view->output; |
| 2721 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2722 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2723 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2724 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2725 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2726 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2727 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2728 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2729 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2730 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2731 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2732 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2733 | } |
| 2734 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2735 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2736 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2737 | shell_surface_move, |
| 2738 | shell_surface_resize, |
| 2739 | shell_surface_set_toplevel, |
| 2740 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2741 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2742 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2743 | shell_surface_set_maximized, |
| 2744 | shell_surface_set_title, |
| 2745 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2746 | }; |
| 2747 | |
| 2748 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2749 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2750 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2751 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2752 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2753 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2754 | remove_popup_grab(shsurf); |
| 2755 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2756 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2757 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2758 | shell_surface_is_top_fullscreen(shsurf)) |
| 2759 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2760 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2761 | if (shsurf->fullscreen.black_view) |
| 2762 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2763 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2764 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2765 | * we can always remove the listener. |
| 2766 | */ |
| 2767 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2768 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2769 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2770 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2771 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2772 | weston_view_destroy(shsurf->view); |
| 2773 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2774 | wl_list_remove(&shsurf->link); |
| 2775 | free(shsurf); |
| 2776 | } |
| 2777 | |
| 2778 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2779 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2780 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2781 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2782 | |
| 2783 | destroy_shell_surface(shsurf); |
| 2784 | } |
| 2785 | |
| 2786 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2787 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2788 | { |
| 2789 | struct shell_surface *shsurf = container_of(listener, |
| 2790 | struct shell_surface, |
| 2791 | surface_destroy_listener); |
| 2792 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2793 | if (shsurf->resource) |
| 2794 | wl_resource_destroy(shsurf->resource); |
| 2795 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2796 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2797 | } |
| 2798 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2799 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2800 | 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] | 2801 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2802 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2803 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2804 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2805 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2806 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2807 | else |
| 2808 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2809 | } |
| 2810 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2811 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2812 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2813 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2814 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2815 | struct shell_surface *shsurf; |
| 2816 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2817 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2818 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2819 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2820 | } |
| 2821 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2822 | shsurf = calloc(1, sizeof *shsurf); |
| 2823 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2824 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2825 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2826 | } |
| 2827 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2828 | shsurf->view = weston_view_create(surface); |
| 2829 | if (!shsurf->view) { |
| 2830 | weston_log("no memory to allocate shell surface\n"); |
| 2831 | free(shsurf); |
| 2832 | return NULL; |
| 2833 | } |
| 2834 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2835 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2836 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2837 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2838 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2839 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2840 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2841 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2842 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2843 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2844 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2845 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2846 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2847 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2848 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2849 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2850 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2851 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2852 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2853 | |
| 2854 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2855 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2856 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2857 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2858 | /* empty when not in use */ |
| 2859 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2860 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2861 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2862 | wl_list_init(&shsurf->workspace_transform.link); |
| 2863 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2864 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2865 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2866 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2867 | shsurf->client = client; |
| 2868 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2869 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2870 | } |
| 2871 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2872 | static struct weston_view * |
| 2873 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2874 | { |
| 2875 | return shsurf->view; |
| 2876 | } |
| 2877 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2878 | static void |
| 2879 | shell_get_shell_surface(struct wl_client *client, |
| 2880 | struct wl_resource *resource, |
| 2881 | uint32_t id, |
| 2882 | struct wl_resource *surface_resource) |
| 2883 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2884 | struct weston_surface *surface = |
| 2885 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2886 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2887 | struct shell_surface *shsurf; |
| 2888 | |
| 2889 | if (get_shell_surface(surface)) { |
| 2890 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2891 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2892 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2893 | return; |
| 2894 | } |
| 2895 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2896 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2897 | if (!shsurf) { |
| 2898 | wl_resource_post_error(surface_resource, |
| 2899 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2900 | "surface->configure already set"); |
| 2901 | return; |
| 2902 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2903 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2904 | shsurf->resource = |
| 2905 | wl_resource_create(client, |
| 2906 | &wl_shell_surface_interface, 1, id); |
| 2907 | wl_resource_set_implementation(shsurf->resource, |
| 2908 | &shell_surface_implementation, |
| 2909 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 2913 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2914 | }; |
| 2915 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2916 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 2917 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 2918 | |
| 2919 | static int |
| 2920 | screensaver_timeout(void *data) |
| 2921 | { |
| 2922 | struct desktop_shell *shell = data; |
| 2923 | |
| 2924 | shell_fade(shell, FADE_OUT); |
| 2925 | |
| 2926 | return 1; |
| 2927 | } |
| 2928 | |
| 2929 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2930 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2931 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2932 | struct desktop_shell *shell = |
| 2933 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2934 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2935 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2936 | |
| 2937 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 2938 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2942 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2943 | { |
| 2944 | if (shell->screensaver.binding) |
| 2945 | return; |
| 2946 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2947 | if (!shell->screensaver.path) { |
| 2948 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2949 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2950 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2951 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2952 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2953 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2954 | return; |
| 2955 | } |
| 2956 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2957 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2958 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2959 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2960 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2961 | } |
| 2962 | |
| 2963 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2964 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2965 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2966 | if (shell->screensaver.process.pid == 0) |
| 2967 | return; |
| 2968 | |
| 2969 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2973 | 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] | 2974 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2975 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2976 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2977 | if (width == 0) |
| 2978 | return; |
| 2979 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2980 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 2981 | if (v->output == ev->output && v != ev) { |
| 2982 | weston_view_unmap(v); |
| 2983 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2984 | } |
| 2985 | } |
| 2986 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2987 | 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] | 2988 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2989 | if (wl_list_empty(&ev->layer_link)) { |
| 2990 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 2991 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2996 | 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] | 2997 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2998 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2999 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3000 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3001 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3002 | |
| 3003 | configure_static_view(view, &shell->background_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3007 | desktop_shell_set_background(struct wl_client *client, |
| 3008 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3009 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3010 | struct wl_resource *surface_resource) |
| 3011 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3012 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3013 | struct weston_surface *surface = |
| 3014 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3015 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3016 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3017 | if (surface->configure) { |
| 3018 | wl_resource_post_error(surface_resource, |
| 3019 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3020 | "surface role already assigned"); |
| 3021 | return; |
| 3022 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3023 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3024 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3025 | weston_view_destroy(view); |
| 3026 | view = weston_view_create(surface); |
| 3027 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3028 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3029 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3030 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3031 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3032 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3033 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3034 | surface->output->width, |
| 3035 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3039 | 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] | 3040 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3041 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3042 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3043 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3044 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3045 | |
| 3046 | configure_static_view(view, &shell->panel_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3050 | desktop_shell_set_panel(struct wl_client *client, |
| 3051 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3052 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3053 | struct wl_resource *surface_resource) |
| 3054 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3055 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3056 | struct weston_surface *surface = |
| 3057 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3058 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3059 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3060 | if (surface->configure) { |
| 3061 | wl_resource_post_error(surface_resource, |
| 3062 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3063 | "surface role already assigned"); |
| 3064 | return; |
| 3065 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3066 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3067 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3068 | weston_view_destroy(view); |
| 3069 | view = weston_view_create(surface); |
| 3070 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3071 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3072 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3073 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3074 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3075 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3076 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3077 | surface->output->width, |
| 3078 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3079 | } |
| 3080 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3081 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3082 | 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] | 3083 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3084 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3085 | struct weston_view *view; |
| 3086 | |
| 3087 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3088 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3089 | if (width == 0) |
| 3090 | return; |
| 3091 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3092 | surface->width = width; |
| 3093 | surface->height = height; |
| 3094 | view->geometry.width = width; |
| 3095 | view->geometry.height = height; |
| 3096 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3097 | |
| 3098 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3099 | wl_list_insert(&shell->lock_layer.view_list, |
| 3100 | &view->layer_link); |
| 3101 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3102 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3107 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3108 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3109 | struct desktop_shell *shell = |
| 3110 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3111 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3112 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3113 | shell->lock_surface = NULL; |
| 3114 | } |
| 3115 | |
| 3116 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3117 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3118 | struct wl_resource *resource, |
| 3119 | struct wl_resource *surface_resource) |
| 3120 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3121 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3122 | struct weston_surface *surface = |
| 3123 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3124 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3125 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3126 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3127 | if (!shell->locked) |
| 3128 | return; |
| 3129 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3130 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3131 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3132 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3133 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3134 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3135 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3136 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3137 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3138 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3142 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3143 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3144 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3145 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3146 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3147 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3148 | wl_list_remove(&shell->lock_layer.link); |
| 3149 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3150 | &shell->fullscreen_layer.link); |
| 3151 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3152 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3153 | if (shell->showing_input_panels) { |
| 3154 | wl_list_insert(&shell->panel_layer.link, |
| 3155 | &shell->input_panel_layer.link); |
| 3156 | wl_list_insert(&shell->input_panel_layer.link, |
| 3157 | &ws->layer.link); |
| 3158 | } else { |
| 3159 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3160 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3161 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3162 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3163 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3164 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3165 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3166 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | static void |
| 3170 | desktop_shell_unlock(struct wl_client *client, |
| 3171 | struct wl_resource *resource) |
| 3172 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3173 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3174 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3175 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3176 | |
| 3177 | if (shell->locked) |
| 3178 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3179 | } |
| 3180 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3181 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3182 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3183 | struct wl_resource *resource, |
| 3184 | struct wl_resource *surface_resource) |
| 3185 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3186 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3187 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3188 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3189 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3190 | } |
| 3191 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3192 | static void |
| 3193 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3194 | struct wl_resource *resource) |
| 3195 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3196 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3197 | |
| 3198 | shell_fade_startup(shell); |
| 3199 | } |
| 3200 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3201 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3202 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3203 | desktop_shell_set_panel, |
| 3204 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3205 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3206 | desktop_shell_set_grab_surface, |
| 3207 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3208 | }; |
| 3209 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3210 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3211 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3212 | { |
| 3213 | struct shell_surface *shsurf; |
| 3214 | |
| 3215 | shsurf = get_shell_surface(surface); |
| 3216 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3217 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3218 | return shsurf->type; |
| 3219 | } |
| 3220 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3221 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3222 | 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] | 3223 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3224 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3225 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3226 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3227 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3228 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3229 | if (surface == NULL) |
| 3230 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3231 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3232 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3233 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3234 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3235 | return; |
| 3236 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3237 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3241 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3242 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3243 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3244 | struct weston_surface *surface; |
| 3245 | struct shell_surface *shsurf; |
| 3246 | |
| 3247 | surface = weston_surface_get_main_surface(focus); |
| 3248 | if (surface == NULL) |
| 3249 | return; |
| 3250 | |
| 3251 | shsurf = get_shell_surface(surface); |
| 3252 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3253 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
| 3254 | return; |
| 3255 | |
| 3256 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3257 | } |
| 3258 | |
| 3259 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3260 | 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] | 3261 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3262 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3263 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3264 | uint32_t edges = 0; |
| 3265 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3266 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3267 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3268 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3269 | if (surface == NULL) |
| 3270 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3271 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3272 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3273 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3274 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3275 | return; |
| 3276 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3277 | weston_view_from_global(shsurf->view, |
| 3278 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3279 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3280 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3282 | if (x < shsurf->view->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3283 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3284 | else if (x < 2 * shsurf->view->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3285 | edges |= 0; |
| 3286 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3287 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3288 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3289 | if (y < shsurf->view->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3290 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3291 | else if (y < 2 * shsurf->view->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3292 | edges |= 0; |
| 3293 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3294 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3295 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3296 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3300 | 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] | 3301 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3302 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3303 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3304 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3305 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3306 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3307 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3308 | /* XXX: broken for windows containing sub-surfaces */ |
| 3309 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3310 | if (surface == NULL) |
| 3311 | return; |
| 3312 | |
| 3313 | shsurf = get_shell_surface(surface); |
| 3314 | if (!shsurf) |
| 3315 | return; |
| 3316 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3317 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3318 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3319 | if (shsurf->view->alpha > 1.0) |
| 3320 | shsurf->view->alpha = 1.0; |
| 3321 | if (shsurf->view->alpha < step) |
| 3322 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3323 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3324 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3325 | weston_surface_damage(surface); |
| 3326 | } |
| 3327 | |
| 3328 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3329 | 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] | 3330 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3331 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3332 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3333 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3334 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3335 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3336 | |
| 3337 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3338 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3339 | wl_fixed_to_double(seat->pointer->x), |
| 3340 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3341 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3342 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3343 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3344 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3345 | increment = -output->zoom.increment; |
| 3346 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3347 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3348 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3349 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3350 | else |
| 3351 | increment = 0; |
| 3352 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3353 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3354 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3355 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3356 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3357 | else if (output->zoom.level > output->zoom.max_level) |
| 3358 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3359 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3360 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3361 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3362 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3363 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3364 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3365 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3366 | } |
| 3367 | } |
| 3368 | } |
| 3369 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3370 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3371 | 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] | 3372 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3373 | { |
| 3374 | do_zoom(seat, time, 0, axis, value); |
| 3375 | } |
| 3376 | |
| 3377 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3378 | 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] | 3379 | void *data) |
| 3380 | { |
| 3381 | do_zoom(seat, time, key, 0, 0); |
| 3382 | } |
| 3383 | |
| 3384 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3385 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3386 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3387 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3388 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3389 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3390 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3394 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 3395 | |
| 3396 | struct alt_tab { |
| 3397 | struct desktop_shell *shell; |
| 3398 | struct weston_keyboard_grab grab; |
| 3399 | |
| 3400 | struct wl_list *current; |
| 3401 | |
| 3402 | struct wl_list preview_list; |
| 3403 | }; |
| 3404 | |
| 3405 | struct alt_tab_preview { |
| 3406 | struct alt_tab *alt_tab; |
| 3407 | |
| 3408 | struct weston_view *view; |
| 3409 | struct weston_transform transform; |
| 3410 | |
| 3411 | struct wl_listener listener; |
| 3412 | |
| 3413 | struct wl_list link; |
| 3414 | }; |
| 3415 | |
| 3416 | static void |
| 3417 | alt_tab_next(struct alt_tab *alt_tab) |
| 3418 | { |
| 3419 | alt_tab->current = alt_tab->current->next; |
| 3420 | |
| 3421 | /* Make sure we're not pointing to the list header e.g. after |
| 3422 | * cycling through the whole list. */ |
| 3423 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3424 | alt_tab->current = alt_tab->current->next; |
| 3425 | } |
| 3426 | |
| 3427 | static void |
| 3428 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 3429 | { |
| 3430 | struct alt_tab_preview *preview, *next; |
| 3431 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 3432 | |
| 3433 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 3434 | preview = wl_container_of(alt_tab->current, preview, link); |
| 3435 | |
| 3436 | activate(alt_tab->shell, preview->view->surface, |
| 3437 | (struct weston_seat *) keyboard->seat); |
| 3438 | } |
| 3439 | |
| 3440 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 3441 | wl_list_remove(&preview->link); |
| 3442 | wl_list_remove(&preview->listener.link); |
| 3443 | weston_view_destroy(preview->view); |
| 3444 | free(preview); |
| 3445 | } |
| 3446 | |
| 3447 | weston_keyboard_end_grab(keyboard); |
| 3448 | if (keyboard->input_method_resource) |
| 3449 | keyboard->grab = &keyboard->input_method_grab; |
| 3450 | |
| 3451 | free(alt_tab); |
| 3452 | } |
| 3453 | |
| 3454 | static void |
| 3455 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3456 | { |
| 3457 | struct alt_tab_preview *preview = |
| 3458 | container_of(listener, struct alt_tab_preview, listener); |
| 3459 | struct alt_tab *alt_tab = preview->alt_tab; |
| 3460 | int advance = 0; |
| 3461 | |
| 3462 | /* If the preview that we're removing is the currently selected one, |
| 3463 | * we want to move to the next one. So we move to ->prev and then |
| 3464 | * call _next() after removing the preview. */ |
| 3465 | if (alt_tab->current == &preview->link) { |
| 3466 | alt_tab->current = alt_tab->current->prev; |
| 3467 | advance = 1; |
| 3468 | } |
| 3469 | |
| 3470 | wl_list_remove(&preview->listener.link); |
| 3471 | wl_list_remove(&preview->link); |
| 3472 | |
| 3473 | free(preview); |
| 3474 | |
| 3475 | if (advance) |
| 3476 | alt_tab_next(alt_tab); |
| 3477 | |
| 3478 | /* If the last preview goes away, stop the alt-tab */ |
| 3479 | if (wl_list_empty(alt_tab->current)) |
| 3480 | alt_tab_destroy(alt_tab); |
| 3481 | } |
| 3482 | |
| 3483 | static void |
| 3484 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 3485 | uint32_t time, uint32_t key, uint32_t state_w) |
| 3486 | { |
| 3487 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3488 | enum wl_keyboard_key_state state = state_w; |
| 3489 | |
| 3490 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 3491 | alt_tab_next(alt_tab); |
| 3492 | } |
| 3493 | |
| 3494 | static void |
| 3495 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 3496 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3497 | uint32_t mods_locked, uint32_t group) |
| 3498 | { |
| 3499 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3500 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 3501 | |
| 3502 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 3503 | alt_tab_destroy(alt_tab); |
| 3504 | } |
| 3505 | |
| 3506 | static void |
| 3507 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 3508 | { |
| 3509 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3510 | |
| 3511 | alt_tab_destroy(alt_tab); |
| 3512 | } |
| 3513 | |
| 3514 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 3515 | alt_tab_key, |
| 3516 | alt_tab_modifier, |
| 3517 | alt_tab_cancel, |
| 3518 | }; |
| 3519 | |
| 3520 | static int |
| 3521 | view_for_alt_tab(struct weston_view *view) |
| 3522 | { |
| 3523 | if (!get_shell_surface(view->surface)) |
| 3524 | return 0; |
| 3525 | |
| 3526 | if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT) |
| 3527 | return 0; |
| 3528 | |
| 3529 | if (view != get_default_view(view->surface)) |
| 3530 | return 0; |
| 3531 | |
| 3532 | return 1; |
| 3533 | } |
| 3534 | |
| 3535 | static void |
| 3536 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 3537 | void *data) |
| 3538 | { |
| 3539 | struct alt_tab *alt_tab; |
| 3540 | struct desktop_shell *shell = data; |
| 3541 | struct weston_output *output = get_default_output(shell->compositor); |
| 3542 | struct workspace *ws; |
| 3543 | struct weston_view *view; |
| 3544 | int num_surfaces = 0; |
| 3545 | int x, y, side, margin; |
| 3546 | |
| 3547 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3548 | |
| 3549 | if (view_for_alt_tab(view)) |
| 3550 | num_surfaces++; |
| 3551 | } |
| 3552 | |
| 3553 | if (!num_surfaces) |
| 3554 | return; |
| 3555 | |
| 3556 | alt_tab = malloc(sizeof *alt_tab); |
| 3557 | if (!alt_tab) |
| 3558 | return; |
| 3559 | |
| 3560 | alt_tab->shell = shell; |
| 3561 | wl_list_init(&alt_tab->preview_list); |
| 3562 | alt_tab->current = &alt_tab->preview_list; |
| 3563 | |
| 3564 | restore_all_output_modes(shell->compositor); |
| 3565 | lower_fullscreen_layer(alt_tab->shell); |
| 3566 | |
| 3567 | alt_tab->grab.interface = &alt_tab_grab; |
| 3568 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 3569 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 3570 | |
| 3571 | ws = get_current_workspace(shell); |
| 3572 | |
| 3573 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 3574 | * and/or add a black surrounding background à la gnome-shell */ |
| 3575 | |
| 3576 | /* Determine the size for each preview */ |
| 3577 | side = output->width / num_surfaces; |
| 3578 | if (side > 200) |
| 3579 | side = 200; |
| 3580 | margin = side / 4; |
| 3581 | side -= margin; |
| 3582 | |
| 3583 | x = margin; |
| 3584 | y = (output->height - side) / 2; |
| 3585 | |
| 3586 | /* Create a view for each surface */ |
| 3587 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3588 | struct alt_tab_preview *preview; |
| 3589 | struct weston_view *v; |
| 3590 | float scale; |
| 3591 | |
| 3592 | if (!view_for_alt_tab(view)) |
| 3593 | continue; |
| 3594 | |
| 3595 | preview = malloc(sizeof *preview); |
| 3596 | if (!preview) { |
| 3597 | alt_tab_destroy(alt_tab); |
| 3598 | return; |
| 3599 | } |
| 3600 | |
| 3601 | preview->alt_tab = alt_tab; |
| 3602 | |
| 3603 | preview->view = v = weston_view_create(view->surface); |
| 3604 | v->output = view->output; |
| 3605 | weston_view_restack(v, &ws->layer.view_list); |
| 3606 | weston_view_configure(v, x, y, view->geometry.width, view->geometry.height); |
| 3607 | |
| 3608 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 3609 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 3610 | |
| 3611 | if (view->geometry.width > view->geometry.height) |
| 3612 | scale = side / (float) view->geometry.width; |
| 3613 | else |
| 3614 | scale = side / (float) view->geometry.height; |
| 3615 | |
| 3616 | wl_list_insert(&v->geometry.transformation_list, |
| 3617 | &preview->transform.link); |
| 3618 | weston_matrix_init(&preview->transform.matrix); |
| 3619 | weston_matrix_scale(&preview->transform.matrix, |
| 3620 | scale, scale, 1.0f); |
| 3621 | |
| 3622 | weston_view_geometry_dirty(v); |
| 3623 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 3624 | |
| 3625 | /* Insert at the end of the list */ |
| 3626 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 3627 | |
| 3628 | x += side + margin; |
| 3629 | } |
| 3630 | |
| 3631 | /* Start at the second preview so a simple <alt>tab changes window. |
| 3632 | * We set `current' to the first preview and not the second because |
| 3633 | * we're going to receive a key press callback for the initial |
| 3634 | * <alt>tab which will make `current' point to the second element. */ |
| 3635 | alt_tab_next(alt_tab); |
| 3636 | } |
| 3637 | |
| 3638 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3639 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3640 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3641 | { |
| 3642 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3643 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3644 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3645 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3646 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3647 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3648 | weston_pointer_move(pointer, x, y); |
| 3649 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3650 | if (!shsurf) |
| 3651 | return; |
| 3652 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3653 | cx = 0.5f * shsurf->view->geometry.width; |
| 3654 | cy = 0.5f * shsurf->view->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3655 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3656 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3657 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3658 | r = sqrtf(dx * dx + dy * dy); |
| 3659 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3660 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3661 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3662 | |
| 3663 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3664 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3665 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3666 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3667 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3668 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3669 | |
| 3670 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3671 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3672 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3673 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3674 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3675 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3676 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3677 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3678 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3679 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3680 | wl_list_init(&shsurf->rotation.transform.link); |
| 3681 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3682 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3683 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3684 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3685 | /* We need to adjust the position of the surface |
| 3686 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3687 | cposx = shsurf->view->geometry.x + cx; |
| 3688 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3689 | dposx = rotate->center.x - cposx; |
| 3690 | dposy = rotate->center.y - cposy; |
| 3691 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3692 | weston_view_set_position(shsurf->view, |
| 3693 | shsurf->view->geometry.x + dposx, |
| 3694 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3695 | } |
| 3696 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3697 | /* Repaint implies weston_surface_update_transform(), which |
| 3698 | * lazily applies the damage due to rotation update. |
| 3699 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3700 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3704 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3705 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3706 | { |
| 3707 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3708 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3709 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3710 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3711 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3712 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3713 | if (pointer->button_count == 0 && |
| 3714 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3715 | if (shsurf) |
| 3716 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3717 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3718 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3719 | free(rotate); |
| 3720 | } |
| 3721 | } |
| 3722 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3723 | static void |
| 3724 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3725 | { |
| 3726 | struct rotate_grab *rotate = |
| 3727 | container_of(grab, struct rotate_grab, base.grab); |
| 3728 | |
| 3729 | shell_grab_end(&rotate->base); |
| 3730 | free(rotate); |
| 3731 | } |
| 3732 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3733 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3734 | noop_grab_focus, |
| 3735 | rotate_grab_motion, |
| 3736 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3737 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3738 | }; |
| 3739 | |
| 3740 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3741 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3742 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3743 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3744 | float dx, dy; |
| 3745 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3746 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3747 | rotate = malloc(sizeof *rotate); |
| 3748 | if (!rotate) |
| 3749 | return; |
| 3750 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3751 | weston_view_to_global_float(surface->view, |
| 3752 | surface->view->geometry.width * 0.5f, |
| 3753 | surface->view->geometry.height * 0.5f, |
| 3754 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3755 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3756 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3757 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3758 | r = sqrtf(dx * dx + dy * dy); |
| 3759 | if (r > 20.0f) { |
| 3760 | struct weston_matrix inverse; |
| 3761 | |
| 3762 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3763 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3764 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3765 | |
| 3766 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3767 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3768 | } else { |
| 3769 | weston_matrix_init(&surface->rotation.rotation); |
| 3770 | weston_matrix_init(&rotate->rotation); |
| 3771 | } |
| 3772 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3773 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3774 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3778 | 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] | 3779 | void *data) |
| 3780 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3781 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3782 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3783 | struct shell_surface *surface; |
| 3784 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3785 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3786 | if (base_surface == NULL) |
| 3787 | return; |
| 3788 | |
| 3789 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3790 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 3791 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3792 | return; |
| 3793 | |
| 3794 | surface_rotate(surface, seat); |
| 3795 | } |
| 3796 | |
| 3797 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3798 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 3799 | { |
| 3800 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3801 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3802 | |
| 3803 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3804 | wl_list_for_each_reverse_safe(view, prev, |
| 3805 | &shell->fullscreen_layer.view_list, |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3806 | layer_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3807 | weston_view_restack(view, &ws->layer.view_list); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3811 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3812 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3813 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3814 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3815 | struct weston_view *main_view; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3816 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3817 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3818 | struct weston_surface *old_es; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3819 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3820 | main_surface = weston_surface_get_main_surface(es); |
| 3821 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3822 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3823 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3824 | state = ensure_focus_state(shell, seat); |
| 3825 | if (state == NULL) |
| 3826 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3827 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3828 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3829 | state->keyboard_focus = es; |
| 3830 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3831 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3832 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3833 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3834 | case SHELL_SURFACE_FULLSCREEN: |
| 3835 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3836 | shell_stack_fullscreen(get_shell_surface(main_surface)); |
| 3837 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3838 | return; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 3839 | case SHELL_SURFACE_TOPLEVEL: |
| 3840 | case SHELL_SURFACE_TRANSIENT: |
| 3841 | case SHELL_SURFACE_MAXIMIZED: |
| 3842 | case SHELL_SURFACE_POPUP: |
| 3843 | case SHELL_SURFACE_XWAYLAND: |
| 3844 | case SHELL_SURFACE_NONE: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3845 | default: |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3846 | restore_all_output_modes(shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3847 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3848 | main_view = get_default_view(main_surface); |
| 3849 | if (main_view) |
| 3850 | weston_view_restack(main_view, &ws->layer.view_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3851 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3852 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3853 | |
| 3854 | if (shell->focus_animation_type != ANIMATION_NONE) |
| 3855 | 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] | 3856 | } |
| 3857 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3858 | /* no-op func for checking black surface */ |
| 3859 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3860 | 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] | 3861 | { |
| 3862 | } |
| 3863 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3864 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3865 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 3866 | { |
| 3867 | if (es->configure == black_surface_configure) { |
| 3868 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3869 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3870 | return true; |
| 3871 | } |
| 3872 | return false; |
| 3873 | } |
| 3874 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3875 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3876 | activate_binding(struct weston_seat *seat, |
| 3877 | struct desktop_shell *shell, |
| 3878 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3879 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3880 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3881 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3882 | if (!focus) |
| 3883 | return; |
| 3884 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3885 | if (is_black_surface(focus, &main_surface)) |
| 3886 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3887 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3888 | main_surface = weston_surface_get_main_surface(focus); |
| 3889 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3890 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3891 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3892 | activate(shell, focus, seat); |
| 3893 | } |
| 3894 | |
| 3895 | static void |
| 3896 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 3897 | void *data) |
| 3898 | { |
| 3899 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 3900 | return; |
| 3901 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3902 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | static void |
| 3906 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3907 | { |
| 3908 | if (seat->touch->grab != &seat->touch->default_grab) |
| 3909 | return; |
| 3910 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3911 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3915 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3916 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3917 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3918 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3919 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3920 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3921 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3922 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3923 | |
| 3924 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3925 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3926 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3927 | * toplevel layers. This way nothing else can show or receive |
| 3928 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3929 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3930 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3931 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3932 | if (shell->showing_input_panels) |
| 3933 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3934 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3935 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3936 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3937 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3938 | launch_screensaver(shell); |
| 3939 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3940 | /* TODO: disable bindings that should not work while locked. */ |
| 3941 | |
| 3942 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3946 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3947 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3948 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3949 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3950 | return; |
| 3951 | } |
| 3952 | |
| 3953 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3954 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3955 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3956 | return; |
| 3957 | } |
| 3958 | |
| 3959 | if (shell->prepare_event_sent) |
| 3960 | return; |
| 3961 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3962 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3963 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3967 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3968 | { |
| 3969 | struct desktop_shell *shell = data; |
| 3970 | |
| 3971 | shell->fade.animation = NULL; |
| 3972 | |
| 3973 | switch (shell->fade.type) { |
| 3974 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3975 | weston_surface_destroy(shell->fade.view->surface); |
| 3976 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3977 | break; |
| 3978 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3979 | lock(shell); |
| 3980 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame^] | 3981 | default: |
| 3982 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3983 | } |
| 3984 | } |
| 3985 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3986 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3987 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3988 | { |
| 3989 | struct weston_compositor *compositor = shell->compositor; |
| 3990 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3991 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3992 | |
| 3993 | surface = weston_surface_create(compositor); |
| 3994 | if (!surface) |
| 3995 | return NULL; |
| 3996 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3997 | view = weston_view_create(surface); |
| 3998 | if (!view) { |
| 3999 | weston_surface_destroy(surface); |
| 4000 | return NULL; |
| 4001 | } |
| 4002 | |
| 4003 | weston_view_configure(view, 0, 0, 8192, 8192); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4004 | 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] | 4005 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4006 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4007 | pixman_region32_init(&surface->input); |
| 4008 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4009 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | static void |
| 4013 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4014 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4015 | float tint; |
| 4016 | |
| 4017 | switch (type) { |
| 4018 | case FADE_IN: |
| 4019 | tint = 0.0; |
| 4020 | break; |
| 4021 | case FADE_OUT: |
| 4022 | tint = 1.0; |
| 4023 | break; |
| 4024 | default: |
| 4025 | weston_log("shell: invalid fade type\n"); |
| 4026 | return; |
| 4027 | } |
| 4028 | |
| 4029 | shell->fade.type = type; |
| 4030 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4031 | if (shell->fade.view == NULL) { |
| 4032 | shell->fade.view = shell_fade_create_surface(shell); |
| 4033 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4034 | return; |
| 4035 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4036 | shell->fade.view->alpha = 1.0 - tint; |
| 4037 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4038 | } |
| 4039 | |
| 4040 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4041 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4042 | else |
| 4043 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4044 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4045 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4046 | shell_fade_done, shell); |
| 4047 | } |
| 4048 | |
| 4049 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4050 | do_shell_fade_startup(void *data) |
| 4051 | { |
| 4052 | struct desktop_shell *shell = data; |
| 4053 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4054 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4055 | shell_fade(shell, FADE_IN); |
| 4056 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4057 | weston_surface_destroy(shell->fade.view->surface); |
| 4058 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4059 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4060 | } |
| 4061 | |
| 4062 | static void |
| 4063 | shell_fade_startup(struct desktop_shell *shell) |
| 4064 | { |
| 4065 | struct wl_event_loop *loop; |
| 4066 | |
| 4067 | if (!shell->fade.startup_timer) |
| 4068 | return; |
| 4069 | |
| 4070 | wl_event_source_remove(shell->fade.startup_timer); |
| 4071 | shell->fade.startup_timer = NULL; |
| 4072 | |
| 4073 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4074 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4075 | } |
| 4076 | |
| 4077 | static int |
| 4078 | fade_startup_timeout(void *data) |
| 4079 | { |
| 4080 | struct desktop_shell *shell = data; |
| 4081 | |
| 4082 | shell_fade_startup(shell); |
| 4083 | return 0; |
| 4084 | } |
| 4085 | |
| 4086 | static void |
| 4087 | shell_fade_init(struct desktop_shell *shell) |
| 4088 | { |
| 4089 | /* Make compositor output all black, and wait for the desktop-shell |
| 4090 | * client to signal it is ready, then fade in. The timer triggers a |
| 4091 | * fade-in, in case the desktop-shell client takes too long. |
| 4092 | */ |
| 4093 | |
| 4094 | struct wl_event_loop *loop; |
| 4095 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4096 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4097 | weston_log("%s: warning: fade surface already exists\n", |
| 4098 | __func__); |
| 4099 | return; |
| 4100 | } |
| 4101 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4102 | shell->fade.view = shell_fade_create_surface(shell); |
| 4103 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4104 | return; |
| 4105 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4106 | weston_view_update_transform(shell->fade.view); |
| 4107 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4108 | |
| 4109 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4110 | shell->fade.startup_timer = |
| 4111 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4112 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4113 | } |
| 4114 | |
| 4115 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4116 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4117 | { |
| 4118 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4119 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4120 | |
| 4121 | shell_fade(shell, FADE_OUT); |
| 4122 | /* lock() is called from shell_fade_done() */ |
| 4123 | } |
| 4124 | |
| 4125 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4126 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4127 | { |
| 4128 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4129 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4130 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4131 | unlock(shell); |
| 4132 | } |
| 4133 | |
| 4134 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4135 | show_input_panels(struct wl_listener *listener, void *data) |
| 4136 | { |
| 4137 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4138 | container_of(listener, struct desktop_shell, |
| 4139 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4140 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4141 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4142 | shell->text_input.surface = (struct weston_surface*)data; |
| 4143 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4144 | if (shell->showing_input_panels) |
| 4145 | return; |
| 4146 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4147 | shell->showing_input_panels = true; |
| 4148 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4149 | if (!shell->locked) |
| 4150 | wl_list_insert(&shell->panel_layer.link, |
| 4151 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4152 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4153 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4154 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4155 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4156 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4157 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4158 | &ipsurf->view->layer_link); |
| 4159 | weston_view_geometry_dirty(ipsurf->view); |
| 4160 | weston_view_update_transform(ipsurf->view); |
| 4161 | weston_surface_damage(ipsurf->surface); |
| 4162 | weston_slide_run(ipsurf->view, ipsurf->view->geometry.height, |
| 4163 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4164 | } |
| 4165 | } |
| 4166 | |
| 4167 | static void |
| 4168 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4169 | { |
| 4170 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4171 | container_of(listener, struct desktop_shell, |
| 4172 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4173 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4174 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4175 | if (!shell->showing_input_panels) |
| 4176 | return; |
| 4177 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4178 | shell->showing_input_panels = false; |
| 4179 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4180 | if (!shell->locked) |
| 4181 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4182 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4183 | wl_list_for_each_safe(view, next, |
| 4184 | &shell->input_panel_layer.view_list, layer_link) |
| 4185 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4186 | } |
| 4187 | |
| 4188 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4189 | update_input_panels(struct wl_listener *listener, void *data) |
| 4190 | { |
| 4191 | struct desktop_shell *shell = |
| 4192 | container_of(listener, struct desktop_shell, |
| 4193 | update_input_panel_listener); |
| 4194 | |
| 4195 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4196 | } |
| 4197 | |
| 4198 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4199 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4200 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4201 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4202 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4203 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4204 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4205 | |
| 4206 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4207 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4208 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4209 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4213 | weston_view_set_initial_position(struct weston_view *view, |
| 4214 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4215 | { |
| 4216 | struct weston_compositor *compositor = shell->compositor; |
| 4217 | int ix = 0, iy = 0; |
| 4218 | int range_x, range_y; |
| 4219 | int dx, dy, x, y, panel_height; |
| 4220 | struct weston_output *output, *target_output = NULL; |
| 4221 | struct weston_seat *seat; |
| 4222 | |
| 4223 | /* As a heuristic place the new window on the same output as the |
| 4224 | * pointer. Falling back to the output containing 0, 0. |
| 4225 | * |
| 4226 | * TODO: Do something clever for touch too? |
| 4227 | */ |
| 4228 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4229 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4230 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4231 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4232 | break; |
| 4233 | } |
| 4234 | } |
| 4235 | |
| 4236 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4237 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4238 | target_output = output; |
| 4239 | break; |
| 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4244 | weston_view_set_position(view, 10 + random() % 400, |
| 4245 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4246 | return; |
| 4247 | } |
| 4248 | |
| 4249 | /* Valid range within output where the surface will still be onscreen. |
| 4250 | * If this is negative it means that the surface is bigger than |
| 4251 | * output. |
| 4252 | */ |
| 4253 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4254 | range_x = target_output->width - view->geometry.width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4255 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4256 | view->geometry.height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4257 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4258 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4259 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4260 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4261 | dx = 0; |
| 4262 | |
| 4263 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4264 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4265 | else |
| 4266 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4267 | |
| 4268 | x = target_output->x + dx; |
| 4269 | y = target_output->y + dy; |
| 4270 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4271 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4275 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4276 | 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] | 4277 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4278 | struct weston_compositor *compositor = shell->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4279 | struct weston_view *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4280 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4281 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4282 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4283 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4285 | shsurf->view->geometry.width = width; |
| 4286 | shsurf->view->geometry.height = height; |
| 4287 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4288 | |
| 4289 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4290 | switch (shsurf->type) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4291 | case SHELL_SURFACE_TOPLEVEL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4292 | weston_view_set_initial_position(shsurf->view, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4293 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4294 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4295 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4296 | shell_map_fullscreen(shsurf); |
| 4297 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4298 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4299 | /* use surface configure to set the geometry */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4300 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4301 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4302 | &surf_x, &surf_y, NULL, NULL); |
| 4303 | weston_view_set_position(shsurf->view, |
| 4304 | shsurf->output->x - surf_x, |
| 4305 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4306 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4307 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4308 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4309 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4310 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4311 | weston_view_set_position(shsurf->view, |
| 4312 | shsurf->view->geometry.x + sx, |
| 4313 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4314 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4315 | case SHELL_SURFACE_TRANSIENT: |
| 4316 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4317 | default: |
| 4318 | ; |
| 4319 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4320 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 4321 | /* surface stacking order, see also activate() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4322 | switch (shsurf->type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4323 | case SHELL_SURFACE_POPUP: |
| 4324 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4325 | /* TODO: Handle a parent with multiple views */ |
| 4326 | parent = get_default_view(shsurf->parent); |
| 4327 | if (parent) { |
| 4328 | wl_list_remove(&shsurf->view->layer_link); |
| 4329 | wl_list_insert(parent->layer_link.prev, |
| 4330 | &shsurf->view->layer_link); |
| 4331 | } |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4332 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4333 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 4334 | case SHELL_SURFACE_NONE: |
| 4335 | break; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4336 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4337 | case SHELL_SURFACE_TOPLEVEL: |
| 4338 | case SHELL_SURFACE_MAXIMIZED: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4339 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4340 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4341 | wl_list_remove(&shsurf->view->layer_link); |
| 4342 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4343 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4344 | } |
| 4345 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4346 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4347 | weston_view_update_transform(shsurf->view); |
| 4348 | if (shsurf->type == SHELL_SURFACE_MAXIMIZED) { |
| 4349 | shsurf->surface->output = shsurf->output; |
| 4350 | shsurf->view->output = shsurf->output; |
| 4351 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4352 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4353 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4354 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4355 | /* XXX: xwayland's using the same fields for transient type */ |
| 4356 | case SHELL_SURFACE_XWAYLAND: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4357 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4358 | if (shsurf->transient.flags == |
| 4359 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4360 | break; |
| 4361 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4362 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4363 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4364 | if (!shell->locked) { |
| 4365 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4366 | activate(shell, shsurf->surface, seat); |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4367 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4368 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4369 | case SHELL_SURFACE_POPUP: |
| 4370 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4371 | default: |
| 4372 | break; |
| 4373 | } |
| 4374 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4375 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4376 | { |
| 4377 | switch (shell->win_animation_type) { |
| 4378 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4379 | 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] | 4380 | break; |
| 4381 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4382 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4383 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame^] | 4384 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4385 | default: |
| 4386 | break; |
| 4387 | } |
| 4388 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4392 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4393 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4394 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4395 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 4396 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4397 | struct weston_view *view; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4398 | int32_t surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4399 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4400 | shsurf = get_shell_surface(surface); |
| 4401 | if (shsurf) |
| 4402 | surface_type = shsurf->type; |
| 4403 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4404 | /* TODO: |
| 4405 | * This should probably be changed to be more shell_surface |
| 4406 | * dependent |
| 4407 | */ |
| 4408 | wl_list_for_each(view, &surface->views, surface_link) |
| 4409 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4410 | |
| 4411 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4412 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 4413 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4414 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4415 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4416 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4417 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4418 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4419 | NULL, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4420 | shsurf->view->geometry.x = shsurf->output->x - surf_x; |
| 4421 | shsurf->view->geometry.y = shsurf->output->y + |
| 4422 | get_output_panel_height(shell,shsurf->output) - surf_y; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4423 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4424 | case SHELL_SURFACE_TOPLEVEL: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4425 | case SHELL_SURFACE_TRANSIENT: |
| 4426 | case SHELL_SURFACE_POPUP: |
| 4427 | case SHELL_SURFACE_XWAYLAND: |
| 4428 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4429 | default: |
| 4430 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4431 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4432 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4433 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4434 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4435 | wl_list_for_each(view, &surface->views, surface_link) |
| 4436 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4437 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4438 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4439 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4440 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4441 | } |
| 4442 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4443 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4444 | 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] | 4445 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4446 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4447 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4448 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4449 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4450 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4451 | if (!weston_surface_is_mapped(es) && |
| 4452 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4453 | remove_popup_grab(shsurf); |
| 4454 | } |
| 4455 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4456 | if (width == 0) |
| 4457 | return; |
| 4458 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4459 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4460 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4461 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4462 | type_changed = 1; |
| 4463 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4464 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4465 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4466 | map(shell, shsurf, width, height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4467 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4468 | shsurf->view->geometry.width != width || |
| 4469 | shsurf->view->geometry.height != height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4470 | float from_x, from_y; |
| 4471 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4472 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4473 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4474 | 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] | 4475 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4476 | shsurf->view->geometry.x + to_x - from_x, |
| 4477 | shsurf->view->geometry.y + to_y - from_y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4478 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4479 | } |
| 4480 | } |
| 4481 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4482 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4483 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4484 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4485 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4486 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4487 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4488 | struct desktop_shell *shell = |
| 4489 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4490 | |
| 4491 | shell->child.process.pid = 0; |
| 4492 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4493 | |
| 4494 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4495 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4496 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4497 | shell->child.deathstamp = time; |
| 4498 | shell->child.deathcount = 0; |
| 4499 | } |
| 4500 | |
| 4501 | shell->child.deathcount++; |
| 4502 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4503 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4504 | return; |
| 4505 | } |
| 4506 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4507 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4508 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4509 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4510 | } |
| 4511 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4512 | static void |
| 4513 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4514 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4515 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4516 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4517 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4518 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4519 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4520 | desktop_shell_sigchld); |
| 4521 | |
| 4522 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4523 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4527 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4528 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4529 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4530 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4531 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4532 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4533 | if (resource) |
| 4534 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4535 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4536 | } |
| 4537 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4538 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4539 | unbind_desktop_shell(struct wl_resource *resource) |
| 4540 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4541 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4542 | |
| 4543 | if (shell->locked) |
| 4544 | resume_desktop(shell); |
| 4545 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4546 | shell->child.desktop_shell = NULL; |
| 4547 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4551 | bind_desktop_shell(struct wl_client *client, |
| 4552 | void *data, uint32_t version, uint32_t id) |
| 4553 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4554 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4555 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4556 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4557 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4558 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4559 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4560 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4561 | wl_resource_set_implementation(resource, |
| 4562 | &desktop_shell_implementation, |
| 4563 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4564 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4565 | |
| 4566 | if (version < 2) |
| 4567 | shell_fade_startup(shell); |
| 4568 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4569 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4570 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4571 | |
| 4572 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4573 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4574 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4575 | } |
| 4576 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4577 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4578 | 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] | 4579 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4580 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4581 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4582 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4583 | if (width == 0) |
| 4584 | return; |
| 4585 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4586 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4587 | if (!shell->locked) |
| 4588 | return; |
| 4589 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4590 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4591 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4592 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4593 | if (wl_list_empty(&view->layer_link)) { |
| 4594 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4595 | &view->layer_link); |
| 4596 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4597 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4598 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4599 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4600 | } |
| 4601 | } |
| 4602 | |
| 4603 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4604 | screensaver_set_surface(struct wl_client *client, |
| 4605 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4606 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4607 | struct wl_resource *output_resource) |
| 4608 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4609 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4610 | struct weston_surface *surface = |
| 4611 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4612 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4613 | struct weston_view *view, *next; |
| 4614 | |
| 4615 | /* Make sure we only have one view */ |
| 4616 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4617 | weston_view_destroy(view); |
| 4618 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4619 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4620 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4621 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4622 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | static const struct screensaver_interface screensaver_implementation = { |
| 4626 | screensaver_set_surface |
| 4627 | }; |
| 4628 | |
| 4629 | static void |
| 4630 | unbind_screensaver(struct wl_resource *resource) |
| 4631 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4632 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4633 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4634 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | static void |
| 4638 | bind_screensaver(struct wl_client *client, |
| 4639 | void *data, uint32_t version, uint32_t id) |
| 4640 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4641 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4642 | struct wl_resource *resource; |
| 4643 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4644 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4645 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4646 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4647 | wl_resource_set_implementation(resource, |
| 4648 | &screensaver_implementation, |
| 4649 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4650 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4651 | return; |
| 4652 | } |
| 4653 | |
| 4654 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4655 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4656 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4657 | } |
| 4658 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4659 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4660 | 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] | 4661 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4662 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4663 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4664 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4665 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4666 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4667 | if (width == 0) |
| 4668 | return; |
| 4669 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4670 | if (!weston_surface_is_mapped(surface)) { |
| 4671 | if (!shell->showing_input_panels) |
| 4672 | return; |
| 4673 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4674 | show_surface = 1; |
| 4675 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4676 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4677 | 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] | 4678 | |
| 4679 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4680 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4681 | 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] | 4682 | } else { |
Rob Bradford | bdeb5d2 | 2013-07-11 13:20:53 +0100 | [diff] [blame] | 4683 | x = ip_surface->output->x + (ip_surface->output->width - width) / 2; |
| 4684 | y = ip_surface->output->y + ip_surface->output->height - height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4685 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4686 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4687 | weston_view_configure(ip_surface->view, x, y, width, height); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4688 | |
| 4689 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4690 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4691 | &ip_surface->view->layer_link); |
| 4692 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4693 | weston_surface_damage(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4694 | 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] | 4695 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4699 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4700 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4701 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4702 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4703 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4704 | wl_list_remove(&input_panel_surface->link); |
| 4705 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4706 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4707 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4708 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4709 | free(input_panel_surface); |
| 4710 | } |
| 4711 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4712 | static struct input_panel_surface * |
| 4713 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4714 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4715 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4716 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4717 | } else { |
| 4718 | return NULL; |
| 4719 | } |
| 4720 | } |
| 4721 | |
| 4722 | static void |
| 4723 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4724 | { |
| 4725 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4726 | struct input_panel_surface, |
| 4727 | surface_destroy_listener); |
| 4728 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4729 | if (ipsurface->resource) { |
| 4730 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4731 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4732 | destroy_input_panel_surface(ipsurface); |
| 4733 | } |
| 4734 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4735 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4736 | static struct input_panel_surface * |
| 4737 | create_input_panel_surface(struct desktop_shell *shell, |
| 4738 | struct weston_surface *surface) |
| 4739 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4740 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4741 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4742 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4743 | if (!input_panel_surface) |
| 4744 | return NULL; |
| 4745 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4746 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4747 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4748 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4749 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4750 | |
| 4751 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4752 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4753 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4754 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4755 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4756 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4757 | &input_panel_surface->surface_destroy_listener); |
| 4758 | |
| 4759 | wl_list_init(&input_panel_surface->link); |
| 4760 | |
| 4761 | return input_panel_surface; |
| 4762 | } |
| 4763 | |
| 4764 | static void |
| 4765 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4766 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4767 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4768 | uint32_t position) |
| 4769 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4770 | struct input_panel_surface *input_panel_surface = |
| 4771 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4772 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4773 | |
| 4774 | wl_list_insert(&shell->input_panel.surfaces, |
| 4775 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4776 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4777 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4778 | input_panel_surface->panel = 0; |
| 4779 | } |
| 4780 | |
| 4781 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4782 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4783 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4784 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4785 | struct input_panel_surface *input_panel_surface = |
| 4786 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4787 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4788 | |
| 4789 | wl_list_insert(&shell->input_panel.surfaces, |
| 4790 | &input_panel_surface->link); |
| 4791 | |
| 4792 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4793 | } |
| 4794 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4795 | 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] | 4796 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4797 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4798 | }; |
| 4799 | |
| 4800 | static void |
| 4801 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4802 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4803 | struct input_panel_surface *ipsurf = |
| 4804 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4805 | |
| 4806 | destroy_input_panel_surface(ipsurf); |
| 4807 | } |
| 4808 | |
| 4809 | static void |
| 4810 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4811 | struct wl_resource *resource, |
| 4812 | uint32_t id, |
| 4813 | struct wl_resource *surface_resource) |
| 4814 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4815 | struct weston_surface *surface = |
| 4816 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4817 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4818 | struct input_panel_surface *ipsurf; |
| 4819 | |
| 4820 | if (get_input_panel_surface(surface)) { |
| 4821 | wl_resource_post_error(surface_resource, |
| 4822 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4823 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4824 | return; |
| 4825 | } |
| 4826 | |
| 4827 | ipsurf = create_input_panel_surface(shell, surface); |
| 4828 | if (!ipsurf) { |
| 4829 | wl_resource_post_error(surface_resource, |
| 4830 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4831 | "surface->configure already set"); |
| 4832 | return; |
| 4833 | } |
| 4834 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4835 | ipsurf->resource = |
| 4836 | wl_resource_create(client, |
| 4837 | &wl_input_panel_surface_interface, 1, id); |
| 4838 | wl_resource_set_implementation(ipsurf->resource, |
| 4839 | &input_panel_surface_implementation, |
| 4840 | ipsurf, |
| 4841 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4842 | } |
| 4843 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4844 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4845 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4846 | }; |
| 4847 | |
| 4848 | static void |
| 4849 | unbind_input_panel(struct wl_resource *resource) |
| 4850 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4851 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4852 | |
| 4853 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | static void |
| 4857 | bind_input_panel(struct wl_client *client, |
| 4858 | void *data, uint32_t version, uint32_t id) |
| 4859 | { |
| 4860 | struct desktop_shell *shell = data; |
| 4861 | struct wl_resource *resource; |
| 4862 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4863 | resource = wl_resource_create(client, |
| 4864 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4865 | |
| 4866 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4867 | wl_resource_set_implementation(resource, |
| 4868 | &input_panel_implementation, |
| 4869 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4870 | shell->input_panel.binding = resource; |
| 4871 | return; |
| 4872 | } |
| 4873 | |
| 4874 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4875 | "interface object already bound"); |
| 4876 | wl_resource_destroy(resource); |
| 4877 | } |
| 4878 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4879 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4880 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4881 | struct weston_surface *current; |
| 4882 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4883 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4884 | }; |
| 4885 | |
| 4886 | static void |
| 4887 | switcher_next(struct switcher *switcher) |
| 4888 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4889 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4890 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4891 | struct shell_surface *shsurf; |
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) { |
| 4895 | switch (get_shell_surface_type(view->surface)) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4896 | case SHELL_SURFACE_TOPLEVEL: |
| 4897 | case SHELL_SURFACE_FULLSCREEN: |
| 4898 | case SHELL_SURFACE_MAXIMIZED: |
| 4899 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4900 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4901 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4902 | next = view->surface; |
| 4903 | prev = view->surface; |
| 4904 | view->alpha = 0.25; |
| 4905 | weston_view_geometry_dirty(view); |
| 4906 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4907 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4908 | case SHELL_SURFACE_TRANSIENT: |
| 4909 | case SHELL_SURFACE_POPUP: |
| 4910 | case SHELL_SURFACE_XWAYLAND: |
| 4911 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4912 | default: |
| 4913 | break; |
| 4914 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4915 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4916 | if (is_black_surface(view->surface, NULL)) { |
| 4917 | view->alpha = 0.25; |
| 4918 | weston_view_geometry_dirty(view); |
| 4919 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4920 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | if (next == NULL) |
| 4924 | next = first; |
| 4925 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4926 | if (next == NULL) |
| 4927 | return; |
| 4928 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4929 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4930 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4931 | |
| 4932 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4933 | wl_list_for_each(view, &next->views, surface_link) |
| 4934 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4935 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4936 | shsurf = get_shell_surface(switcher->current); |
| 4937 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4938 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4939 | } |
| 4940 | |
| 4941 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4942 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4943 | { |
| 4944 | struct switcher *switcher = |
| 4945 | container_of(listener, struct switcher, listener); |
| 4946 | |
| 4947 | switcher_next(switcher); |
| 4948 | } |
| 4949 | |
| 4950 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4951 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4952 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4953 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4954 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4955 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4956 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4957 | 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] | 4958 | if (is_focus_view(view)) |
| 4959 | continue; |
| 4960 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4961 | view->alpha = 1.0; |
| 4962 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4963 | } |
| 4964 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4965 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4966 | activate(switcher->shell, switcher->current, |
| 4967 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4968 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4969 | weston_keyboard_end_grab(keyboard); |
| 4970 | if (keyboard->input_method_resource) |
| 4971 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4972 | free(switcher); |
| 4973 | } |
| 4974 | |
| 4975 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4976 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4977 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4978 | { |
| 4979 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4980 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4981 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4982 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4983 | switcher_next(switcher); |
| 4984 | } |
| 4985 | |
| 4986 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4987 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4988 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4989 | uint32_t mods_locked, uint32_t group) |
| 4990 | { |
| 4991 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4992 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4993 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4994 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4995 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4996 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4997 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4998 | static void |
| 4999 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5000 | { |
| 5001 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5002 | |
| 5003 | switcher_destroy(switcher); |
| 5004 | } |
| 5005 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5006 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5007 | switcher_key, |
| 5008 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5009 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5010 | }; |
| 5011 | |
| 5012 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5013 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5014 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5015 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5016 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5017 | struct switcher *switcher; |
| 5018 | |
| 5019 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5020 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5021 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5022 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5023 | wl_list_init(&switcher->listener.link); |
| 5024 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5025 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5026 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5027 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5028 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5029 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5030 | switcher_next(switcher); |
| 5031 | } |
| 5032 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5033 | struct exposay_surface { |
| 5034 | struct desktop_shell *shell; |
| 5035 | struct weston_surface *surface; |
| 5036 | struct weston_view *view; |
| 5037 | struct wl_list link; |
| 5038 | |
| 5039 | int x; |
| 5040 | int y; |
| 5041 | int width; |
| 5042 | int height; |
| 5043 | double scale; |
| 5044 | |
| 5045 | int row; |
| 5046 | int column; |
| 5047 | |
| 5048 | /* The animations only apply a transformation for their own lifetime, |
| 5049 | * and don't have an option to indefinitely maintain the |
| 5050 | * transformation in a steady state - so, we apply our own once the |
| 5051 | * animation has finished. */ |
| 5052 | struct weston_transform transform; |
| 5053 | }; |
| 5054 | |
| 5055 | static void exposay_set_state(struct desktop_shell *shell, |
| 5056 | enum exposay_target_state state, |
| 5057 | struct weston_seat *seat); |
| 5058 | static void exposay_check_state(struct desktop_shell *shell); |
| 5059 | |
| 5060 | static void |
| 5061 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 5062 | { |
| 5063 | shell->exposay.in_flight++; |
| 5064 | } |
| 5065 | |
| 5066 | static void |
| 5067 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5068 | { |
| 5069 | if (--shell->exposay.in_flight > 0) |
| 5070 | return; |
| 5071 | |
| 5072 | exposay_check_state(shell); |
| 5073 | } |
| 5074 | |
| 5075 | static void |
| 5076 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5077 | { |
| 5078 | struct exposay_surface *esurface = data; |
| 5079 | |
| 5080 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5081 | &esurface->transform.link); |
| 5082 | weston_matrix_init(&esurface->transform.matrix); |
| 5083 | weston_matrix_scale(&esurface->transform.matrix, |
| 5084 | esurface->scale, esurface->scale, 1.0f); |
| 5085 | weston_matrix_translate(&esurface->transform.matrix, |
| 5086 | esurface->x - esurface->view->geometry.x, |
| 5087 | esurface->y - esurface->view->geometry.y, |
| 5088 | 0); |
| 5089 | |
| 5090 | weston_view_geometry_dirty(esurface->view); |
| 5091 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5092 | |
| 5093 | exposay_in_flight_dec(esurface->shell); |
| 5094 | } |
| 5095 | |
| 5096 | static void |
| 5097 | exposay_animate_in(struct exposay_surface *esurface) |
| 5098 | { |
| 5099 | exposay_in_flight_inc(esurface->shell); |
| 5100 | |
| 5101 | weston_move_scale_run(esurface->view, |
| 5102 | esurface->x - esurface->view->geometry.x, |
| 5103 | esurface->y - esurface->view->geometry.y, |
| 5104 | 1.0, esurface->scale, 0, |
| 5105 | exposay_animate_in_done, esurface); |
| 5106 | } |
| 5107 | |
| 5108 | static void |
| 5109 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5110 | { |
| 5111 | struct exposay_surface *esurface = data; |
| 5112 | struct desktop_shell *shell = esurface->shell; |
| 5113 | |
| 5114 | wl_list_remove(&esurface->link); |
| 5115 | free(esurface); |
| 5116 | |
| 5117 | exposay_in_flight_dec(shell); |
| 5118 | } |
| 5119 | |
| 5120 | static void |
| 5121 | exposay_animate_out(struct exposay_surface *esurface) |
| 5122 | { |
| 5123 | exposay_in_flight_inc(esurface->shell); |
| 5124 | |
| 5125 | /* Remove the static transformation set up by |
| 5126 | * exposay_transform_in_done(). */ |
| 5127 | wl_list_remove(&esurface->transform.link); |
| 5128 | weston_view_geometry_dirty(esurface->view); |
| 5129 | |
| 5130 | weston_move_scale_run(esurface->view, |
| 5131 | esurface->x - esurface->view->geometry.x, |
| 5132 | esurface->y - esurface->view->geometry.y, |
| 5133 | 1.0, esurface->scale, 1, |
| 5134 | exposay_animate_out_done, esurface); |
| 5135 | } |
| 5136 | |
| 5137 | static void |
| 5138 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5139 | struct exposay_surface *esurface) |
| 5140 | { |
| 5141 | struct weston_view *view = NULL; |
| 5142 | |
| 5143 | if (esurface) { |
| 5144 | shell->exposay.row_current = esurface->row; |
| 5145 | shell->exposay.column_current = esurface->column; |
| 5146 | view = esurface->view; |
| 5147 | } |
| 5148 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5149 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5150 | shell->exposay.focus_current = view; |
| 5151 | } |
| 5152 | |
| 5153 | static int |
| 5154 | exposay_is_animating(struct desktop_shell *shell) |
| 5155 | { |
| 5156 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5157 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5158 | return 0; |
| 5159 | |
| 5160 | return (shell->exposay.in_flight > 0); |
| 5161 | } |
| 5162 | |
| 5163 | static void |
| 5164 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5165 | { |
| 5166 | struct exposay_surface *esurface; |
| 5167 | |
| 5168 | if (exposay_is_animating(shell)) |
| 5169 | return; |
| 5170 | |
| 5171 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5172 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5173 | continue; |
| 5174 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5175 | continue; |
| 5176 | |
| 5177 | exposay_highlight_surface(shell, esurface); |
| 5178 | return; |
| 5179 | } |
| 5180 | } |
| 5181 | |
| 5182 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5183 | * aspect ratio into account really. Also needs to be notified of surface |
| 5184 | * addition and removal and adjust layout/animate accordingly. */ |
| 5185 | static enum exposay_layout_state |
| 5186 | exposay_layout(struct desktop_shell *shell) |
| 5187 | { |
| 5188 | struct workspace *workspace = shell->exposay.workspace; |
| 5189 | struct weston_compositor *compositor = shell->compositor; |
| 5190 | struct weston_output *output = get_default_output(compositor); |
| 5191 | struct weston_view *view; |
| 5192 | struct exposay_surface *esurface; |
| 5193 | int w, h; |
| 5194 | int i; |
| 5195 | int last_row_removed = 0; |
| 5196 | |
| 5197 | wl_list_init(&shell->exposay.surface_list); |
| 5198 | |
| 5199 | shell->exposay.num_surfaces = 0; |
| 5200 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5201 | if (!get_shell_surface(view->surface)) |
| 5202 | continue; |
| 5203 | shell->exposay.num_surfaces++; |
| 5204 | } |
| 5205 | |
| 5206 | if (shell->exposay.num_surfaces == 0) { |
| 5207 | shell->exposay.grid_size = 0; |
| 5208 | shell->exposay.hpadding_outer = 0; |
| 5209 | shell->exposay.vpadding_outer = 0; |
| 5210 | shell->exposay.padding_inner = 0; |
| 5211 | shell->exposay.surface_size = 0; |
| 5212 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5213 | } |
| 5214 | |
| 5215 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5216 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5217 | * around the outside and 80px internal padding between surfaces, and |
| 5218 | * maximise the area made available to surfaces after this, but only |
| 5219 | * to a maximum of 1/3rd the total output size. |
| 5220 | * |
| 5221 | * If we can't make a square grid, add one extra row at the bottom |
| 5222 | * which will have a smaller number of columns. |
| 5223 | * |
| 5224 | * XXX: Surely there has to be a better way to express this maths, |
| 5225 | * right?! |
| 5226 | */ |
| 5227 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5228 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5229 | shell->exposay.grid_size++; |
| 5230 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5231 | |
| 5232 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5233 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5234 | shell->exposay.padding_inner = 80; |
| 5235 | |
| 5236 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5237 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5238 | w /= shell->exposay.grid_size; |
| 5239 | |
| 5240 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5241 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5242 | h /= shell->exposay.grid_size; |
| 5243 | |
| 5244 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5245 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5246 | shell->exposay.surface_size = output->width / 2; |
| 5247 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5248 | shell->exposay.surface_size = output->height / 2; |
| 5249 | |
| 5250 | i = 0; |
| 5251 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5252 | int pad; |
| 5253 | |
| 5254 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5255 | |
| 5256 | if (!get_shell_surface(view->surface)) |
| 5257 | continue; |
| 5258 | |
| 5259 | esurface = malloc(sizeof(*esurface)); |
| 5260 | if (!esurface) { |
| 5261 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5262 | shell->exposay.seat); |
| 5263 | break; |
| 5264 | } |
| 5265 | |
| 5266 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5267 | esurface->shell = shell; |
| 5268 | esurface->view = view; |
| 5269 | |
| 5270 | esurface->row = i / shell->exposay.grid_size; |
| 5271 | esurface->column = i % shell->exposay.grid_size; |
| 5272 | |
| 5273 | esurface->x = shell->exposay.hpadding_outer; |
| 5274 | esurface->x += pad * esurface->column; |
| 5275 | esurface->y = shell->exposay.vpadding_outer; |
| 5276 | esurface->y += pad * esurface->row; |
| 5277 | |
| 5278 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5279 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5280 | |
| 5281 | if (view->geometry.width > view->geometry.height) |
| 5282 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.width; |
| 5283 | else |
| 5284 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.height; |
| 5285 | esurface->width = view->geometry.width * esurface->scale; |
| 5286 | esurface->height = view->geometry.height * esurface->scale; |
| 5287 | |
| 5288 | if (shell->exposay.focus_current == esurface->view) |
| 5289 | exposay_highlight_surface(shell, esurface); |
| 5290 | |
| 5291 | exposay_animate_in(esurface); |
| 5292 | |
| 5293 | i++; |
| 5294 | } |
| 5295 | |
| 5296 | weston_compositor_schedule_repaint(shell->compositor); |
| 5297 | |
| 5298 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5299 | } |
| 5300 | |
| 5301 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5302 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 5303 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5304 | { |
| 5305 | struct desktop_shell *shell = |
| 5306 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5307 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5308 | weston_pointer_move(grab->pointer, x, y); |
| 5309 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5310 | exposay_pick(shell, |
| 5311 | wl_fixed_to_int(grab->pointer->x), |
| 5312 | wl_fixed_to_int(grab->pointer->y)); |
| 5313 | } |
| 5314 | |
| 5315 | static void |
| 5316 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5317 | uint32_t state_w) |
| 5318 | { |
| 5319 | struct desktop_shell *shell = |
| 5320 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5321 | struct weston_seat *seat = grab->pointer->seat; |
| 5322 | enum wl_pointer_button_state state = state_w; |
| 5323 | |
| 5324 | if (button != BTN_LEFT) |
| 5325 | return; |
| 5326 | |
| 5327 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5328 | * releasing on a different surface. */ |
| 5329 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5330 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5331 | return; |
| 5332 | } |
| 5333 | |
| 5334 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5335 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5336 | else |
| 5337 | shell->exposay.clicked = NULL; |
| 5338 | } |
| 5339 | |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5340 | static void |
| 5341 | exposay_pointer_grab_cancel(struct weston_pointer_grab *grab) |
| 5342 | { |
| 5343 | struct desktop_shell *shell = |
| 5344 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5345 | |
| 5346 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5347 | } |
| 5348 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5349 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5350 | noop_grab_focus, |
| 5351 | exposay_motion, |
| 5352 | exposay_button, |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5353 | exposay_pointer_grab_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5354 | }; |
| 5355 | |
| 5356 | static int |
| 5357 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5358 | { |
| 5359 | struct exposay_surface *esurface; |
| 5360 | |
| 5361 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5362 | if (esurface->row != row || esurface->column != column) |
| 5363 | continue; |
| 5364 | |
| 5365 | exposay_highlight_surface(shell, esurface); |
| 5366 | return 1; |
| 5367 | } |
| 5368 | |
| 5369 | return 0; |
| 5370 | } |
| 5371 | |
| 5372 | static void |
| 5373 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5374 | uint32_t state_w) |
| 5375 | { |
| 5376 | struct weston_seat *seat = grab->keyboard->seat; |
| 5377 | struct desktop_shell *shell = |
| 5378 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5379 | enum wl_keyboard_key_state state = state_w; |
| 5380 | |
| 5381 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5382 | return; |
| 5383 | |
| 5384 | switch (key) { |
| 5385 | case KEY_ESC: |
| 5386 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5387 | break; |
| 5388 | case KEY_ENTER: |
| 5389 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5390 | break; |
| 5391 | case KEY_UP: |
| 5392 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5393 | shell->exposay.column_current); |
| 5394 | break; |
| 5395 | case KEY_DOWN: |
| 5396 | /* Special case for trying to move to the bottom row when it |
| 5397 | * has fewer items than all the others. */ |
| 5398 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5399 | shell->exposay.column_current) && |
| 5400 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5401 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5402 | (shell->exposay.num_surfaces % |
| 5403 | shell->exposay.grid_size) - 1); |
| 5404 | } |
| 5405 | break; |
| 5406 | case KEY_LEFT: |
| 5407 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5408 | shell->exposay.column_current - 1); |
| 5409 | break; |
| 5410 | case KEY_RIGHT: |
| 5411 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5412 | shell->exposay.column_current + 1); |
| 5413 | break; |
| 5414 | case KEY_TAB: |
| 5415 | /* Try to move right, then down (and to the leftmost column), |
| 5416 | * then if all else fails, to the top left. */ |
| 5417 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5418 | shell->exposay.column_current + 1) && |
| 5419 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5420 | exposay_maybe_move(shell, 0, 0); |
| 5421 | break; |
| 5422 | default: |
| 5423 | break; |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | static void |
| 5428 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5429 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5430 | uint32_t mods_locked, uint32_t group) |
| 5431 | { |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5432 | struct desktop_shell *shell = |
| 5433 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5434 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 5435 | |
| 5436 | /* We want to know when mod has been pressed and released. |
| 5437 | * FIXME: There is a problem here: if mod is pressed, then a key |
| 5438 | * is pressed and released, then mod is released, we will treat that |
| 5439 | * as if only mod had been pressed and released. */ |
| 5440 | if (seat->modifier_state) { |
| 5441 | if (seat->modifier_state == shell->binding_modifier) { |
| 5442 | shell->exposay.mod_pressed = true; |
| 5443 | } else { |
| 5444 | shell->exposay.mod_invalid = true; |
| 5445 | } |
| 5446 | } else { |
| 5447 | if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid) |
| 5448 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5449 | |
| 5450 | shell->exposay.mod_invalid = false; |
| 5451 | shell->exposay.mod_pressed = false; |
| 5452 | } |
| 5453 | |
| 5454 | return; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5455 | } |
| 5456 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5457 | static void |
| 5458 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 5459 | { |
| 5460 | struct desktop_shell *shell = |
| 5461 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5462 | |
| 5463 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5464 | } |
| 5465 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5466 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5467 | exposay_key, |
| 5468 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5469 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5470 | }; |
| 5471 | |
| 5472 | /** |
| 5473 | * Called when the transition from overview -> inactive has completed. |
| 5474 | */ |
| 5475 | static enum exposay_layout_state |
| 5476 | exposay_set_inactive(struct desktop_shell *shell) |
| 5477 | { |
| 5478 | struct weston_seat *seat = shell->exposay.seat; |
| 5479 | |
| 5480 | weston_keyboard_end_grab(seat->keyboard); |
| 5481 | weston_pointer_end_grab(seat->pointer); |
| 5482 | if (seat->keyboard->input_method_resource) |
| 5483 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5484 | |
| 5485 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5486 | } |
| 5487 | |
| 5488 | /** |
| 5489 | * Begins the transition from overview to inactive. */ |
| 5490 | static enum exposay_layout_state |
| 5491 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5492 | { |
| 5493 | struct exposay_surface *esurface; |
| 5494 | |
| 5495 | /* Call activate() before we start the animations to avoid |
| 5496 | * animating back the old state and then immediately transitioning |
| 5497 | * to the new. */ |
| 5498 | if (switch_focus && shell->exposay.focus_current) |
| 5499 | activate(shell, shell->exposay.focus_current->surface, |
| 5500 | shell->exposay.seat); |
| 5501 | else if (shell->exposay.focus_prev) |
| 5502 | activate(shell, shell->exposay.focus_prev->surface, |
| 5503 | shell->exposay.seat); |
| 5504 | |
| 5505 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5506 | exposay_animate_out(esurface); |
| 5507 | weston_compositor_schedule_repaint(shell->compositor); |
| 5508 | |
| 5509 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5510 | } |
| 5511 | |
| 5512 | static enum exposay_layout_state |
| 5513 | exposay_transition_active(struct desktop_shell *shell) |
| 5514 | { |
| 5515 | struct weston_seat *seat = shell->exposay.seat; |
| 5516 | |
| 5517 | shell->exposay.workspace = get_current_workspace(shell); |
| 5518 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5519 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5520 | shell->exposay.clicked = NULL; |
| 5521 | wl_list_init(&shell->exposay.surface_list); |
| 5522 | |
| 5523 | lower_fullscreen_layer(shell); |
| 5524 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5525 | weston_keyboard_start_grab(seat->keyboard, |
| 5526 | &shell->exposay.grab_kbd); |
| 5527 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5528 | |
| 5529 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5530 | weston_pointer_start_grab(seat->pointer, |
| 5531 | &shell->exposay.grab_ptr); |
| 5532 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5533 | seat->pointer->x, seat->pointer->y); |
| 5534 | |
| 5535 | return exposay_layout(shell); |
| 5536 | } |
| 5537 | |
| 5538 | static void |
| 5539 | exposay_check_state(struct desktop_shell *shell) |
| 5540 | { |
| 5541 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5542 | int do_switch = 0; |
| 5543 | |
| 5544 | /* Don't do anything whilst animations are running, just store up |
| 5545 | * target state changes and only act on them when the animations have |
| 5546 | * completed. */ |
| 5547 | if (exposay_is_animating(shell)) |
| 5548 | return; |
| 5549 | |
| 5550 | switch (shell->exposay.state_target) { |
| 5551 | case EXPOSAY_TARGET_OVERVIEW: |
| 5552 | switch (shell->exposay.state_cur) { |
| 5553 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5554 | goto out; |
| 5555 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5556 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5557 | break; |
| 5558 | default: |
| 5559 | state_new = exposay_transition_active(shell); |
| 5560 | break; |
| 5561 | } |
| 5562 | break; |
| 5563 | |
| 5564 | case EXPOSAY_TARGET_SWITCH: |
| 5565 | do_switch = 1; /* fallthrough */ |
| 5566 | case EXPOSAY_TARGET_CANCEL: |
| 5567 | switch (shell->exposay.state_cur) { |
| 5568 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5569 | goto out; |
| 5570 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5571 | state_new = exposay_set_inactive(shell); |
| 5572 | break; |
| 5573 | default: |
| 5574 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5575 | break; |
| 5576 | } |
| 5577 | |
| 5578 | break; |
| 5579 | } |
| 5580 | |
| 5581 | out: |
| 5582 | shell->exposay.state_cur = state_new; |
| 5583 | } |
| 5584 | |
| 5585 | static void |
| 5586 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5587 | struct weston_seat *seat) |
| 5588 | { |
| 5589 | shell->exposay.state_target = state; |
| 5590 | shell->exposay.seat = seat; |
| 5591 | exposay_check_state(shell); |
| 5592 | } |
| 5593 | |
| 5594 | static void |
| 5595 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5596 | void *data) |
| 5597 | { |
| 5598 | struct desktop_shell *shell = data; |
| 5599 | |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5600 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5601 | } |
| 5602 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5603 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5604 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5605 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5606 | { |
| 5607 | struct weston_compositor *compositor = data; |
| 5608 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5609 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5610 | |
| 5611 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5612 | * control on the primary display. We'd have to extend later if we |
| 5613 | * ever get support for setting backlights on random desktop LCD |
| 5614 | * panels though */ |
| 5615 | output = get_default_output(compositor); |
| 5616 | if (!output) |
| 5617 | return; |
| 5618 | |
| 5619 | if (!output->set_backlight) |
| 5620 | return; |
| 5621 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5622 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5623 | backlight_new = output->backlight_current - 25; |
| 5624 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5625 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5626 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5627 | if (backlight_new < 5) |
| 5628 | backlight_new = 5; |
| 5629 | if (backlight_new > 255) |
| 5630 | backlight_new = 255; |
| 5631 | |
| 5632 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5633 | output->set_backlight(output, output->backlight_current); |
| 5634 | } |
| 5635 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5636 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5637 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5638 | struct weston_seat *seat; |
| 5639 | uint32_t key[2]; |
| 5640 | int key_released[2]; |
| 5641 | }; |
| 5642 | |
| 5643 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5644 | 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] | 5645 | uint32_t key, uint32_t state) |
| 5646 | { |
| 5647 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5648 | struct weston_compositor *ec = db->seat->compositor; |
| 5649 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5650 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5651 | uint32_t serial; |
| 5652 | int send = 0, terminate = 0; |
| 5653 | int check_binding = 1; |
| 5654 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5655 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5656 | |
| 5657 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5658 | /* Do not run bindings on key releases */ |
| 5659 | check_binding = 0; |
| 5660 | |
| 5661 | for (i = 0; i < 2; i++) |
| 5662 | if (key == db->key[i]) |
| 5663 | db->key_released[i] = 1; |
| 5664 | |
| 5665 | if (db->key_released[0] && db->key_released[1]) { |
| 5666 | /* All key releases been swalled so end the grab */ |
| 5667 | terminate = 1; |
| 5668 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5669 | /* Should not swallow release of other keys */ |
| 5670 | send = 1; |
| 5671 | } |
| 5672 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5673 | /* Do not check bindings for the first press of the binding |
| 5674 | * key. This allows it to be used as a debug shortcut. |
| 5675 | * We still need to swallow this event. */ |
| 5676 | check_binding = 0; |
| 5677 | } else if (db->key[1]) { |
| 5678 | /* If we already ran a binding don't process another one since |
| 5679 | * we can't keep track of all the binding keys that were |
| 5680 | * pressed in order to swallow the release events. */ |
| 5681 | send = 1; |
| 5682 | check_binding = 0; |
| 5683 | } |
| 5684 | |
| 5685 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5686 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5687 | key, state)) { |
| 5688 | /* We ran a binding so swallow the press and keep the |
| 5689 | * grab to swallow the released too. */ |
| 5690 | send = 0; |
| 5691 | terminate = 0; |
| 5692 | db->key[1] = key; |
| 5693 | } else { |
| 5694 | /* Terminate the grab since the key pressed is not a |
| 5695 | * debug binding key. */ |
| 5696 | send = 1; |
| 5697 | terminate = 1; |
| 5698 | } |
| 5699 | } |
| 5700 | |
| 5701 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5702 | serial = wl_display_next_serial(display); |
| 5703 | resource_list = &grab->keyboard->focus_resource_list; |
| 5704 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5705 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5706 | } |
| 5707 | } |
| 5708 | |
| 5709 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5710 | weston_keyboard_end_grab(grab->keyboard); |
| 5711 | if (grab->keyboard->input_method_resource) |
| 5712 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5713 | free(db); |
| 5714 | } |
| 5715 | } |
| 5716 | |
| 5717 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5718 | 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] | 5719 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5720 | uint32_t mods_locked, uint32_t group) |
| 5721 | { |
| 5722 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5723 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5724 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5725 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5726 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5727 | wl_resource_for_each(resource, resource_list) { |
| 5728 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5729 | mods_latched, mods_locked, group); |
| 5730 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5731 | } |
| 5732 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5733 | static void |
| 5734 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5735 | { |
| 5736 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5737 | |
| 5738 | weston_keyboard_end_grab(grab->keyboard); |
| 5739 | free(db); |
| 5740 | } |
| 5741 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5742 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5743 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5744 | debug_binding_modifiers, |
| 5745 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5746 | }; |
| 5747 | |
| 5748 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5749 | 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] | 5750 | { |
| 5751 | struct debug_binding_grab *grab; |
| 5752 | |
| 5753 | grab = calloc(1, sizeof *grab); |
| 5754 | if (!grab) |
| 5755 | return; |
| 5756 | |
| 5757 | grab->seat = (struct weston_seat *) seat; |
| 5758 | grab->key[0] = key; |
| 5759 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5760 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5761 | } |
| 5762 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5763 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5764 | 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] | 5765 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5766 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5767 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5768 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5769 | struct desktop_shell *shell = data; |
| 5770 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5771 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5772 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5773 | focus_surface = seat->keyboard->focus; |
| 5774 | if (!focus_surface) |
| 5775 | return; |
| 5776 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5777 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5778 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5779 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5780 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5781 | |
| 5782 | /* Skip clients that we launched ourselves (the credentials of |
| 5783 | * the socketpair is ours) */ |
| 5784 | if (pid == getpid()) |
| 5785 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5786 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5787 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5791 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5792 | uint32_t key, void *data) |
| 5793 | { |
| 5794 | struct desktop_shell *shell = data; |
| 5795 | unsigned int new_index = shell->workspaces.current; |
| 5796 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5797 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5798 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5799 | if (new_index != 0) |
| 5800 | new_index--; |
| 5801 | |
| 5802 | change_workspace(shell, new_index); |
| 5803 | } |
| 5804 | |
| 5805 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5806 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5807 | uint32_t key, void *data) |
| 5808 | { |
| 5809 | struct desktop_shell *shell = data; |
| 5810 | unsigned int new_index = shell->workspaces.current; |
| 5811 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5812 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5813 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5814 | if (new_index < shell->workspaces.num - 1) |
| 5815 | new_index++; |
| 5816 | |
| 5817 | change_workspace(shell, new_index); |
| 5818 | } |
| 5819 | |
| 5820 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5821 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5822 | uint32_t key, void *data) |
| 5823 | { |
| 5824 | struct desktop_shell *shell = data; |
| 5825 | unsigned int new_index; |
| 5826 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5827 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5828 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5829 | new_index = key - KEY_F1; |
| 5830 | if (new_index >= shell->workspaces.num) |
| 5831 | new_index = shell->workspaces.num - 1; |
| 5832 | |
| 5833 | change_workspace(shell, new_index); |
| 5834 | } |
| 5835 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5836 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5837 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5838 | uint32_t key, void *data) |
| 5839 | { |
| 5840 | struct desktop_shell *shell = data; |
| 5841 | unsigned int new_index = shell->workspaces.current; |
| 5842 | |
| 5843 | if (shell->locked) |
| 5844 | return; |
| 5845 | |
| 5846 | if (new_index != 0) |
| 5847 | new_index--; |
| 5848 | |
| 5849 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5850 | } |
| 5851 | |
| 5852 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5853 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5854 | uint32_t key, void *data) |
| 5855 | { |
| 5856 | struct desktop_shell *shell = data; |
| 5857 | unsigned int new_index = shell->workspaces.current; |
| 5858 | |
| 5859 | if (shell->locked) |
| 5860 | return; |
| 5861 | |
| 5862 | if (new_index < shell->workspaces.num - 1) |
| 5863 | new_index++; |
| 5864 | |
| 5865 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5866 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5867 | |
| 5868 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5869 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5870 | { |
| 5871 | struct shell_output *output_listener = |
| 5872 | container_of(listener, struct shell_output, destroy_listener); |
| 5873 | |
| 5874 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5875 | wl_list_remove(&output_listener->link); |
| 5876 | free(output_listener); |
| 5877 | } |
| 5878 | |
| 5879 | static void |
| 5880 | create_shell_output(struct desktop_shell *shell, |
| 5881 | struct weston_output *output) |
| 5882 | { |
| 5883 | struct shell_output *shell_output; |
| 5884 | |
| 5885 | shell_output = zalloc(sizeof *shell_output); |
| 5886 | if (shell_output == NULL) |
| 5887 | return; |
| 5888 | |
| 5889 | shell_output->output = output; |
| 5890 | shell_output->shell = shell; |
| 5891 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5892 | wl_signal_add(&output->destroy_signal, |
| 5893 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5894 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5895 | } |
| 5896 | |
| 5897 | static void |
| 5898 | handle_output_create(struct wl_listener *listener, void *data) |
| 5899 | { |
| 5900 | struct desktop_shell *shell = |
| 5901 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5902 | struct weston_output *output = (struct weston_output *)data; |
| 5903 | |
| 5904 | create_shell_output(shell, output); |
| 5905 | } |
| 5906 | |
| 5907 | static void |
| 5908 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5909 | struct desktop_shell *shell) |
| 5910 | { |
| 5911 | struct weston_output *output; |
| 5912 | |
| 5913 | wl_list_init(&shell->output_list); |
| 5914 | wl_list_for_each(output, &ec->output_list, link) |
| 5915 | create_shell_output(shell, output); |
| 5916 | |
| 5917 | shell->output_create_listener.notify = handle_output_create; |
| 5918 | wl_signal_add(&ec->output_created_signal, |
| 5919 | &shell->output_create_listener); |
| 5920 | } |
| 5921 | |
| 5922 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5923 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5924 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5925 | struct desktop_shell *shell = |
| 5926 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5927 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5928 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5929 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5930 | if (shell->child.client) |
| 5931 | wl_client_destroy(shell->child.client); |
| 5932 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5933 | wl_list_remove(&shell->idle_listener.link); |
| 5934 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5935 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 5936 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5937 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5938 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5939 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5940 | wl_list_remove(&shell_output->link); |
| 5941 | free(shell_output); |
| 5942 | } |
| 5943 | |
| 5944 | wl_list_remove(&shell->output_create_listener.link); |
| 5945 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5946 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5947 | workspace_destroy(*ws); |
| 5948 | wl_array_release(&shell->workspaces.array); |
| 5949 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5950 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5951 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5952 | free(shell); |
| 5953 | } |
| 5954 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5955 | static void |
| 5956 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5957 | { |
| 5958 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5959 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5960 | |
| 5961 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5962 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5963 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5964 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 5965 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 5966 | MODIFIER_ALT, |
| 5967 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5968 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5969 | click_to_activate_binding, |
| 5970 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5971 | weston_compositor_add_touch_binding(ec, 0, |
| 5972 | touch_to_activate_binding, |
| 5973 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5974 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5975 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5976 | surface_opacity_binding, NULL); |
| 5977 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5978 | MODIFIER_SUPER, zoom_axis_binding, |
| 5979 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5980 | |
| 5981 | /* configurable bindings */ |
| 5982 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5983 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5984 | zoom_key_binding, NULL); |
| 5985 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5986 | zoom_key_binding, NULL); |
| 5987 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5988 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5989 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5990 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5991 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5992 | |
| 5993 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5994 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5995 | rotate_binding, NULL); |
| 5996 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5997 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5998 | shell); |
| 5999 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6000 | ec); |
| 6001 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6002 | backlight_binding, ec); |
| 6003 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6004 | ec); |
| 6005 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6006 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6007 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6008 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6009 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6010 | workspace_up_binding, shell); |
| 6011 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6012 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6013 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6014 | workspace_move_surface_up_binding, |
| 6015 | shell); |
| 6016 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6017 | workspace_move_surface_down_binding, |
| 6018 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6019 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6020 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 6021 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6022 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6023 | if (shell->workspaces.num > 1) { |
| 6024 | num_workspace_bindings = shell->workspaces.num; |
| 6025 | if (num_workspace_bindings > 6) |
| 6026 | num_workspace_bindings = 6; |
| 6027 | for (i = 0; i < num_workspace_bindings; i++) |
| 6028 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6029 | workspace_f_binding, |
| 6030 | shell); |
| 6031 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6032 | |
| 6033 | /* Debug bindings */ |
| 6034 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6035 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6036 | } |
| 6037 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6038 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6039 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6040 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6041 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6042 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6043 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6044 | struct workspace **pws; |
| 6045 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6046 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6047 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6048 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6049 | if (shell == NULL) |
| 6050 | return -1; |
| 6051 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6052 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6053 | |
| 6054 | shell->destroy_listener.notify = shell_destroy; |
| 6055 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6056 | shell->idle_listener.notify = idle_handler; |
| 6057 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6058 | shell->wake_listener.notify = wake_handler; |
| 6059 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6060 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6061 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6062 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6063 | 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] | 6064 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6065 | 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] | 6066 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6067 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6068 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6069 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6070 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6071 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6072 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6073 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6074 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6075 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6076 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6077 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6078 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6079 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6080 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6081 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6082 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6083 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6084 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6085 | |
| 6086 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6087 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6088 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6089 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6090 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6091 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6092 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6093 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6094 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6095 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6096 | if (pws == NULL) |
| 6097 | return -1; |
| 6098 | |
| 6099 | *pws = workspace_create(); |
| 6100 | if (*pws == NULL) |
| 6101 | return -1; |
| 6102 | } |
| 6103 | activate_workspace(shell, 0); |
| 6104 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6105 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6106 | wl_list_init(&shell->workspaces.animation.link); |
| 6107 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6108 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6109 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6110 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6111 | return -1; |
| 6112 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6113 | if (wl_global_create(ec->wl_display, |
| 6114 | &desktop_shell_interface, 2, |
| 6115 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6116 | return -1; |
| 6117 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6118 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6119 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6120 | return -1; |
| 6121 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6122 | 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] | 6123 | shell, bind_input_panel) == NULL) |
| 6124 | return -1; |
| 6125 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6126 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6127 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6128 | return -1; |
| 6129 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6130 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6131 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6132 | setup_output_destroy_handler(ec, shell); |
| 6133 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6134 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6135 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6136 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6137 | shell->screensaver.timer = |
| 6138 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6139 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6140 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6141 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6142 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6143 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6144 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6145 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6146 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6147 | return 0; |
| 6148 | } |