Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
| 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
| 15 | * |
| 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 23 | */ |
| 24 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 29 | #include <stdbool.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 34 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 36 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 37 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 39 | #include "desktop-shell-server-protocol.h" |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 40 | #include "input-method-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 41 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 42 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 43 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 44 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 45 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 46 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 47 | enum animation_type { |
| 48 | ANIMATION_NONE, |
| 49 | |
| 50 | ANIMATION_ZOOM, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 51 | ANIMATION_FADE, |
| 52 | ANIMATION_DIM_LAYER, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 53 | }; |
| 54 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 55 | enum fade_type { |
| 56 | FADE_IN, |
| 57 | FADE_OUT |
| 58 | }; |
| 59 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 60 | enum exposay_target_state { |
| 61 | EXPOSAY_TARGET_OVERVIEW, /* show all windows */ |
| 62 | EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */ |
| 63 | EXPOSAY_TARGET_SWITCH, /* return to normal, switch focus */ |
| 64 | }; |
| 65 | |
| 66 | enum exposay_layout_state { |
| 67 | EXPOSAY_LAYOUT_INACTIVE = 0, /* normal desktop */ |
| 68 | EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE, /* in transition to normal */ |
| 69 | EXPOSAY_LAYOUT_OVERVIEW, /* show all windows */ |
| 70 | EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW, /* in transition to all windows */ |
| 71 | }; |
| 72 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 73 | struct focus_state { |
| 74 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 75 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 76 | struct weston_surface *keyboard_focus; |
| 77 | struct wl_list link; |
| 78 | struct wl_listener seat_destroy_listener; |
| 79 | struct wl_listener surface_destroy_listener; |
| 80 | }; |
| 81 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 82 | struct focus_surface { |
| 83 | struct weston_surface *surface; |
| 84 | struct weston_view *view; |
| 85 | struct weston_transform workspace_transform; |
| 86 | }; |
| 87 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 88 | struct workspace { |
| 89 | struct weston_layer layer; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 90 | |
| 91 | struct wl_list focus_list; |
| 92 | struct wl_listener seat_destroyed_listener; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 93 | |
| 94 | struct focus_surface *fsurf_front; |
| 95 | struct focus_surface *fsurf_back; |
| 96 | struct weston_view_animation *focus_animation; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 99 | struct input_panel_surface { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 100 | struct wl_resource *resource; |
| 101 | struct wl_signal destroy_signal; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 102 | |
| 103 | struct desktop_shell *shell; |
| 104 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 105 | struct wl_list link; |
| 106 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 107 | struct weston_view *view; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 108 | struct wl_listener surface_destroy_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 109 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 110 | struct weston_output *output; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 111 | uint32_t panel; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 114 | struct shell_output { |
| 115 | struct desktop_shell *shell; |
| 116 | struct weston_output *output; |
| 117 | struct wl_listener destroy_listener; |
| 118 | struct wl_list link; |
| 119 | }; |
| 120 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 121 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 122 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 123 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 124 | struct wl_listener idle_listener; |
| 125 | struct wl_listener wake_listener; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 126 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 127 | struct wl_listener show_input_panel_listener; |
| 128 | struct wl_listener hide_input_panel_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 129 | struct wl_listener update_input_panel_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 130 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 131 | struct weston_layer fullscreen_layer; |
| 132 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 133 | struct weston_layer background_layer; |
| 134 | struct weston_layer lock_layer; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 135 | struct weston_layer input_panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 136 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 137 | struct wl_listener pointer_focus_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 138 | struct weston_surface *grab_surface; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 139 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 140 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 141 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 142 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 143 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 144 | |
| 145 | unsigned deathcount; |
| 146 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 147 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 148 | |
| 149 | bool locked; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 150 | bool showing_input_panels; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 151 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 152 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 153 | struct { |
| 154 | struct weston_surface *surface; |
| 155 | pixman_box32_t cursor_rectangle; |
| 156 | } text_input; |
| 157 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 158 | struct weston_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 159 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 160 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 161 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 162 | struct wl_array array; |
| 163 | unsigned int current; |
| 164 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 165 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 166 | struct wl_list client_list; |
| 167 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 168 | struct weston_animation animation; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 169 | struct wl_list anim_sticky_list; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 170 | int anim_dir; |
| 171 | uint32_t anim_timestamp; |
| 172 | double anim_current; |
| 173 | struct workspace *anim_from; |
| 174 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 175 | } workspaces; |
| 176 | |
| 177 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 178 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 179 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 180 | struct wl_resource *binding; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 181 | struct weston_process process; |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 182 | struct wl_event_source *timer; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 183 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 184 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 185 | struct { |
| 186 | struct wl_resource *binding; |
| 187 | struct wl_list surfaces; |
| 188 | } input_panel; |
| 189 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 190 | struct { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 191 | struct weston_view *view; |
| 192 | struct weston_view_animation *animation; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 193 | enum fade_type type; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 194 | struct wl_event_source *startup_timer; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 195 | } fade; |
| 196 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 197 | struct exposay { |
| 198 | /* XXX: Make these exposay_surfaces. */ |
| 199 | struct weston_view *focus_prev; |
| 200 | struct weston_view *focus_current; |
| 201 | struct weston_view *clicked; |
| 202 | struct workspace *workspace; |
| 203 | struct weston_seat *seat; |
| 204 | struct wl_list surface_list; |
| 205 | |
| 206 | struct weston_keyboard_grab grab_kbd; |
| 207 | struct weston_pointer_grab grab_ptr; |
| 208 | |
| 209 | enum exposay_target_state state_target; |
| 210 | enum exposay_layout_state state_cur; |
| 211 | int in_flight; /* number of animations still running */ |
| 212 | |
| 213 | int num_surfaces; |
| 214 | int grid_size; |
| 215 | int surface_size; |
| 216 | |
| 217 | int hpadding_outer; |
| 218 | int vpadding_outer; |
| 219 | int padding_inner; |
| 220 | |
| 221 | int row_current; |
| 222 | int column_current; |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 223 | |
| 224 | bool mod_pressed; |
| 225 | bool mod_invalid; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 226 | } exposay; |
| 227 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 228 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 229 | enum animation_type win_animation_type; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 230 | enum animation_type startup_animation_type; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 231 | enum animation_type focus_animation_type; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 232 | |
| 233 | struct wl_listener output_create_listener; |
| 234 | struct wl_list output_list; |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 235 | |
| 236 | char *client; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 237 | }; |
| 238 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 239 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 240 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 241 | SHELL_SURFACE_TOPLEVEL, |
| 242 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 243 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 244 | SHELL_SURFACE_MAXIMIZED, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 245 | SHELL_SURFACE_POPUP, |
| 246 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 247 | }; |
| 248 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 249 | struct ping_timer { |
| 250 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 251 | uint32_t serial; |
| 252 | }; |
| 253 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 254 | /* |
| 255 | * Surface stacking and ordering. |
| 256 | * |
| 257 | * This is handled using several linked lists of surfaces, organised into |
| 258 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 259 | * above all of the surfaces in the layer below. The set of layers is static and |
| 260 | * in the following order (top-most first): |
| 261 | * • Lock layer (only ever displayed on its own) |
| 262 | * • Cursor layer |
| 263 | * • Fullscreen layer |
| 264 | * • Panel layer |
| 265 | * • Input panel layer |
| 266 | * • Workspace layers |
| 267 | * • Background layer |
| 268 | * |
| 269 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 270 | * display. For example, when locking the screen, all layers except the lock |
| 271 | * layer are removed. |
| 272 | * |
| 273 | * A surface’s layer is modified on configuring the surface, in |
| 274 | * set_surface_type() (which is only called when the surface’s type change is |
| 275 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 276 | * fullscreen) its layer changes too. |
| 277 | * |
| 278 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 279 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 280 | * linked list of its children. When a surface’s layer is updated, so are the |
| 281 | * layers of its children. Note that child surfaces are *not* the same as |
| 282 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 283 | * order. |
| 284 | * |
| 285 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 286 | * have the same parent) only contains weston_surfaces which have a |
| 287 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 288 | * weston_surfaces. This means that the following implication does *not* hold: |
| 289 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 290 | */ |
| 291 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 292 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 293 | struct wl_resource *resource; |
| 294 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 295 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 296 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 297 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 298 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 299 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 300 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 301 | struct wl_list children_list; /* child surfaces of this one */ |
| 302 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 303 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 304 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 305 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 306 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 307 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 308 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 309 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 310 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 311 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 312 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 313 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 314 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 315 | } rotation; |
| 316 | |
| 317 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 318 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 319 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 320 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 321 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 322 | } popup; |
| 323 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 324 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 325 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 326 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 327 | } transient; |
| 328 | |
| 329 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 330 | enum wl_shell_surface_fullscreen_method type; |
| 331 | struct weston_transform transform; /* matrix from x, y */ |
| 332 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 333 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 334 | } fullscreen; |
| 335 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 336 | struct ping_timer *ping_timer; |
| 337 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 338 | struct weston_transform workspace_transform; |
| 339 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 340 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 341 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 342 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 343 | |
| 344 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 345 | }; |
| 346 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 347 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 348 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 349 | struct shell_surface *shsurf; |
| 350 | struct wl_listener shsurf_destroy_listener; |
| 351 | }; |
| 352 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 353 | struct shell_touch_grab { |
| 354 | struct weston_touch_grab grab; |
| 355 | struct shell_surface *shsurf; |
| 356 | struct wl_listener shsurf_destroy_listener; |
| 357 | struct weston_touch *touch; |
| 358 | }; |
| 359 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 360 | struct weston_move_grab { |
| 361 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 362 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 363 | }; |
| 364 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 365 | struct weston_touch_move_grab { |
| 366 | struct shell_touch_grab base; |
| 367 | wl_fixed_t dx, dy; |
| 368 | }; |
| 369 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 370 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 371 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 372 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 373 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 374 | float x; |
| 375 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 376 | } center; |
| 377 | }; |
| 378 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 379 | struct shell_seat { |
| 380 | struct weston_seat *seat; |
| 381 | struct wl_listener seat_destroy_listener; |
| 382 | |
| 383 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 384 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 385 | struct wl_list surfaces_list; |
| 386 | struct wl_client *client; |
| 387 | int32_t initial_up; |
| 388 | } popup_grab; |
| 389 | }; |
| 390 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 391 | static void |
| 392 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 393 | struct weston_seat *seat); |
| 394 | |
| 395 | static struct workspace * |
| 396 | get_current_workspace(struct desktop_shell *shell); |
| 397 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 398 | static struct shell_surface * |
| 399 | get_shell_surface(struct weston_surface *surface); |
| 400 | |
| 401 | static struct desktop_shell * |
| 402 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 403 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 404 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 405 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 406 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 407 | static void |
| 408 | shell_fade_startup(struct desktop_shell *shell); |
| 409 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 410 | static struct shell_seat * |
| 411 | get_shell_seat(struct weston_seat *seat); |
| 412 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 413 | static void |
| 414 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 415 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 416 | static bool |
| 417 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 418 | { |
| 419 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 420 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 421 | |
| 422 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 423 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 424 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 425 | return false; |
| 426 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 427 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 428 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 429 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 430 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 431 | } |
| 432 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 433 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 434 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 435 | { |
| 436 | struct shell_grab *grab; |
| 437 | |
| 438 | grab = container_of(listener, struct shell_grab, |
| 439 | shsurf_destroy_listener); |
| 440 | |
| 441 | grab->shsurf = NULL; |
| 442 | } |
| 443 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 444 | static struct weston_view * |
| 445 | get_default_view(struct weston_surface *surface) |
| 446 | { |
| 447 | struct shell_surface *shsurf; |
| 448 | struct weston_view *view; |
| 449 | |
| 450 | if (!surface || wl_list_empty(&surface->views)) |
| 451 | return NULL; |
| 452 | |
| 453 | shsurf = get_shell_surface(surface); |
| 454 | if (shsurf) |
| 455 | return shsurf->view; |
| 456 | |
| 457 | wl_list_for_each(view, &surface->views, surface_link) |
| 458 | if (weston_view_is_mapped(view)) |
| 459 | return view; |
| 460 | |
| 461 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 462 | } |
| 463 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 464 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 465 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 466 | |
| 467 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 468 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 469 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 470 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 471 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 472 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 473 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 474 | struct desktop_shell *shell = shsurf->shell; |
| 475 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 476 | popup_grab_end(pointer); |
| 477 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 478 | grab->grab.interface = interface; |
| 479 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 480 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 481 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 482 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 483 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 484 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 485 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 486 | if (shell->child.desktop_shell) { |
| 487 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 488 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 489 | weston_pointer_set_focus(pointer, |
| 490 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 491 | wl_fixed_from_int(0), |
| 492 | wl_fixed_from_int(0)); |
| 493 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 497 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 498 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 499 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 500 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 501 | grab->shsurf->grabbed = 0; |
| 502 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 503 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 504 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 508 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 509 | const struct weston_touch_grab_interface *interface, |
| 510 | struct shell_surface *shsurf, |
| 511 | struct weston_touch *touch) |
| 512 | { |
| 513 | struct desktop_shell *shell = shsurf->shell; |
| 514 | |
| 515 | grab->grab.interface = interface; |
| 516 | grab->shsurf = shsurf; |
| 517 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 518 | wl_signal_add(&shsurf->destroy_signal, |
| 519 | &grab->shsurf_destroy_listener); |
| 520 | |
| 521 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 522 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 523 | |
| 524 | weston_touch_start_grab(touch, &grab->grab); |
| 525 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 526 | weston_touch_set_focus(touch->seat, |
| 527 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static void |
| 531 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 532 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 533 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 534 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 535 | grab->shsurf->grabbed = 0; |
| 536 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 537 | |
| 538 | weston_touch_end_grab(grab->touch); |
| 539 | } |
| 540 | |
| 541 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 542 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 543 | struct weston_output *output); |
| 544 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 545 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 546 | get_modifier(char *modifier) |
| 547 | { |
| 548 | if (!modifier) |
| 549 | return MODIFIER_SUPER; |
| 550 | |
| 551 | if (!strcmp("ctrl", modifier)) |
| 552 | return MODIFIER_CTRL; |
| 553 | else if (!strcmp("alt", modifier)) |
| 554 | return MODIFIER_ALT; |
| 555 | else if (!strcmp("super", modifier)) |
| 556 | return MODIFIER_SUPER; |
| 557 | else |
| 558 | return MODIFIER_SUPER; |
| 559 | } |
| 560 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 561 | static enum animation_type |
| 562 | get_animation_type(char *animation) |
| 563 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 564 | if (!strcmp("zoom", animation)) |
| 565 | return ANIMATION_ZOOM; |
| 566 | else if (!strcmp("fade", animation)) |
| 567 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 568 | else if (!strcmp("dim-layer", animation)) |
| 569 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 570 | else |
| 571 | return ANIMATION_NONE; |
| 572 | } |
| 573 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 574 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 575 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 576 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 577 | struct weston_config_section *section; |
| 578 | int duration; |
| 579 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 580 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 581 | section = weston_config_get_section(shell->compositor->config, |
| 582 | "screensaver", NULL, NULL); |
| 583 | weston_config_section_get_string(section, |
| 584 | "path", &shell->screensaver.path, NULL); |
| 585 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 586 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 587 | |
| 588 | section = weston_config_get_section(shell->compositor->config, |
| 589 | "shell", NULL, NULL); |
| 590 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 591 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 592 | shell->client = s; |
| 593 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 594 | "binding-modifier", &s, "super"); |
| 595 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 596 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 597 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 598 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 599 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 600 | weston_config_section_get_string(section, |
| 601 | "startup-animation", &s, "fade"); |
| 602 | shell->startup_animation_type = get_animation_type(s); |
| 603 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 604 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 605 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 606 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 607 | shell->focus_animation_type = get_animation_type(s); |
| 608 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 609 | weston_config_section_get_uint(section, "num-workspaces", |
| 610 | &shell->workspaces.num, |
| 611 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 612 | } |
| 613 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 614 | static struct weston_output * |
| 615 | get_default_output(struct weston_compositor *compositor) |
| 616 | { |
| 617 | return container_of(compositor->output_list.next, |
| 618 | struct weston_output, link); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | /* no-op func for checking focus surface */ |
| 623 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 624 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 625 | { |
| 626 | } |
| 627 | |
| 628 | static struct focus_surface * |
| 629 | get_focus_surface(struct weston_surface *surface) |
| 630 | { |
| 631 | if (surface->configure == focus_surface_configure) |
| 632 | return surface->configure_private; |
| 633 | else |
| 634 | return NULL; |
| 635 | } |
| 636 | |
| 637 | static bool |
| 638 | is_focus_surface (struct weston_surface *es) |
| 639 | { |
| 640 | return (es->configure == focus_surface_configure); |
| 641 | } |
| 642 | |
| 643 | static bool |
| 644 | is_focus_view (struct weston_view *view) |
| 645 | { |
| 646 | return is_focus_surface (view->surface); |
| 647 | } |
| 648 | |
| 649 | static struct focus_surface * |
| 650 | create_focus_surface(struct weston_compositor *ec, |
| 651 | struct weston_output *output) |
| 652 | { |
| 653 | struct focus_surface *fsurf = NULL; |
| 654 | struct weston_surface *surface = NULL; |
| 655 | |
| 656 | fsurf = malloc(sizeof *fsurf); |
| 657 | if (!fsurf) |
| 658 | return NULL; |
| 659 | |
| 660 | fsurf->surface = weston_surface_create(ec); |
| 661 | surface = fsurf->surface; |
| 662 | if (surface == NULL) { |
| 663 | free(fsurf); |
| 664 | return NULL; |
| 665 | } |
| 666 | |
| 667 | surface->configure = focus_surface_configure; |
| 668 | surface->output = output; |
| 669 | surface->configure_private = fsurf; |
| 670 | |
| 671 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 672 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 673 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 674 | surface->width = output->width; |
| 675 | surface->height = output->height; |
| 676 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 677 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 678 | pixman_region32_fini(&surface->opaque); |
| 679 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 680 | output->width, output->height); |
| 681 | pixman_region32_fini(&surface->input); |
| 682 | pixman_region32_init(&surface->input); |
| 683 | |
| 684 | wl_list_init(&fsurf->workspace_transform.link); |
| 685 | |
| 686 | return fsurf; |
| 687 | } |
| 688 | |
| 689 | static void |
| 690 | focus_surface_destroy(struct focus_surface *fsurf) |
| 691 | { |
| 692 | weston_surface_destroy(fsurf->surface); |
| 693 | free(fsurf); |
| 694 | } |
| 695 | |
| 696 | static void |
| 697 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 698 | { |
| 699 | struct workspace *ws = data; |
| 700 | |
| 701 | ws->focus_animation = NULL; |
| 702 | } |
| 703 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 704 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 705 | focus_state_destroy(struct focus_state *state) |
| 706 | { |
| 707 | wl_list_remove(&state->seat_destroy_listener.link); |
| 708 | wl_list_remove(&state->surface_destroy_listener.link); |
| 709 | free(state); |
| 710 | } |
| 711 | |
| 712 | static void |
| 713 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 714 | { |
| 715 | struct focus_state *state = container_of(listener, |
| 716 | struct focus_state, |
| 717 | seat_destroy_listener); |
| 718 | |
| 719 | wl_list_remove(&state->link); |
| 720 | focus_state_destroy(state); |
| 721 | } |
| 722 | |
| 723 | static void |
| 724 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 725 | { |
| 726 | struct focus_state *state = container_of(listener, |
| 727 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 728 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 729 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 730 | struct weston_surface *main_surface, *next; |
| 731 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 732 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 733 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 734 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 735 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 736 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 737 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 738 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 739 | if (is_focus_view(view)) |
| 740 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 741 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 742 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 743 | break; |
| 744 | } |
| 745 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 746 | /* if the focus was a sub-surface, activate its main surface */ |
| 747 | if (main_surface != state->keyboard_focus) |
| 748 | next = main_surface; |
| 749 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 750 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 751 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 752 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 753 | activate(shell, next, state->seat); |
| 754 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 755 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 756 | if (state->ws->focus_animation) |
| 757 | weston_view_animation_destroy(state->ws->focus_animation); |
| 758 | |
| 759 | state->ws->focus_animation = weston_fade_run( |
| 760 | state->ws->fsurf_front->view, |
| 761 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 762 | focus_animation_done, state->ws); |
| 763 | } |
| 764 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 765 | wl_list_remove(&state->link); |
| 766 | focus_state_destroy(state); |
| 767 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 771 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 772 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 773 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 774 | |
| 775 | state = malloc(sizeof *state); |
| 776 | if (state == NULL) |
| 777 | return NULL; |
| 778 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 779 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 780 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 781 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 782 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 783 | |
| 784 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 785 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 786 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 787 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 788 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 789 | |
| 790 | return state; |
| 791 | } |
| 792 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 793 | static struct focus_state * |
| 794 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 795 | { |
| 796 | struct workspace *ws = get_current_workspace(shell); |
| 797 | struct focus_state *state; |
| 798 | |
| 799 | wl_list_for_each(state, &ws->focus_list, link) |
| 800 | if (state->seat == seat) |
| 801 | break; |
| 802 | |
| 803 | if (&state->link == &ws->focus_list) |
| 804 | state = focus_state_create(seat, ws); |
| 805 | |
| 806 | return state; |
| 807 | } |
| 808 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 809 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 810 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 811 | { |
| 812 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 813 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 814 | |
| 815 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 816 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 817 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 818 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | |
| 822 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 823 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 824 | struct weston_seat *seat) |
| 825 | { |
| 826 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 827 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 828 | |
| 829 | wl_list_for_each(state, &ws->focus_list, link) { |
| 830 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 831 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 832 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 833 | return; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | static void |
| 839 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 840 | struct weston_surface *surface) |
| 841 | { |
| 842 | struct focus_state *state; |
| 843 | |
| 844 | wl_list_for_each(state, &ws->focus_list, link) |
| 845 | if (state->keyboard_focus == surface) |
| 846 | state->keyboard_focus = NULL; |
| 847 | } |
| 848 | |
| 849 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 850 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 851 | struct weston_view *from, struct weston_view *to) |
| 852 | { |
| 853 | struct weston_output *output; |
| 854 | bool focus_surface_created = false; |
| 855 | |
| 856 | /* FIXME: Only support dim animation using two layers */ |
| 857 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 858 | return; |
| 859 | |
| 860 | output = get_default_output(shell->compositor); |
| 861 | if (ws->fsurf_front == NULL && (from || to)) { |
| 862 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 863 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 864 | ws->fsurf_front->view->alpha = 0.0; |
| 865 | ws->fsurf_back->view->alpha = 0.0; |
| 866 | focus_surface_created = true; |
| 867 | } else { |
| 868 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 869 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 870 | } |
| 871 | |
| 872 | if (ws->focus_animation) { |
| 873 | weston_view_animation_destroy(ws->focus_animation); |
| 874 | ws->focus_animation = NULL; |
| 875 | } |
| 876 | |
| 877 | if (to) |
| 878 | wl_list_insert(&to->layer_link, |
| 879 | &ws->fsurf_front->view->layer_link); |
| 880 | else if (from) |
| 881 | wl_list_insert(&ws->layer.view_list, |
| 882 | &ws->fsurf_front->view->layer_link); |
| 883 | |
| 884 | if (focus_surface_created) { |
| 885 | ws->focus_animation = weston_fade_run( |
| 886 | ws->fsurf_front->view, |
| 887 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 888 | focus_animation_done, ws); |
| 889 | } else if (from) { |
| 890 | wl_list_insert(&from->layer_link, |
| 891 | &ws->fsurf_back->view->layer_link); |
| 892 | ws->focus_animation = weston_stable_fade_run( |
| 893 | ws->fsurf_front->view, 0.0, |
| 894 | ws->fsurf_back->view, 0.6, |
| 895 | focus_animation_done, ws); |
| 896 | } else if (to) { |
| 897 | wl_list_insert(&ws->layer.view_list, |
| 898 | &ws->fsurf_back->view->layer_link); |
| 899 | ws->focus_animation = weston_stable_fade_run( |
| 900 | ws->fsurf_front->view, 0.0, |
| 901 | ws->fsurf_back->view, 0.6, |
| 902 | focus_animation_done, ws); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 907 | workspace_destroy(struct workspace *ws) |
| 908 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 909 | struct focus_state *state, *next; |
| 910 | |
| 911 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 912 | focus_state_destroy(state); |
| 913 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 914 | if (ws->fsurf_front) |
| 915 | focus_surface_destroy(ws->fsurf_front); |
| 916 | if (ws->fsurf_back) |
| 917 | focus_surface_destroy(ws->fsurf_back); |
| 918 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 919 | free(ws); |
| 920 | } |
| 921 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 922 | static void |
| 923 | seat_destroyed(struct wl_listener *listener, void *data) |
| 924 | { |
| 925 | struct weston_seat *seat = data; |
| 926 | struct focus_state *state, *next; |
| 927 | struct workspace *ws = container_of(listener, |
| 928 | struct workspace, |
| 929 | seat_destroyed_listener); |
| 930 | |
| 931 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 932 | if (state->seat == seat) |
| 933 | wl_list_remove(&state->link); |
| 934 | } |
| 935 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 936 | static struct workspace * |
| 937 | workspace_create(void) |
| 938 | { |
| 939 | struct workspace *ws = malloc(sizeof *ws); |
| 940 | if (ws == NULL) |
| 941 | return NULL; |
| 942 | |
| 943 | weston_layer_init(&ws->layer, NULL); |
| 944 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 945 | wl_list_init(&ws->focus_list); |
| 946 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 947 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 948 | ws->fsurf_front = NULL; |
| 949 | ws->fsurf_back = NULL; |
| 950 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 951 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 952 | return ws; |
| 953 | } |
| 954 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 955 | static int |
| 956 | workspace_is_empty(struct workspace *ws) |
| 957 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 958 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 959 | } |
| 960 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 961 | static struct workspace * |
| 962 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 963 | { |
| 964 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 965 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 966 | pws += index; |
| 967 | return *pws; |
| 968 | } |
| 969 | |
| 970 | static struct workspace * |
| 971 | get_current_workspace(struct desktop_shell *shell) |
| 972 | { |
| 973 | return get_workspace(shell, shell->workspaces.current); |
| 974 | } |
| 975 | |
| 976 | static void |
| 977 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 978 | { |
| 979 | struct workspace *ws; |
| 980 | |
| 981 | ws = get_workspace(shell, index); |
| 982 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 983 | |
| 984 | shell->workspaces.current = index; |
| 985 | } |
| 986 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 987 | static unsigned int |
| 988 | get_output_height(struct weston_output *output) |
| 989 | { |
| 990 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 991 | } |
| 992 | |
| 993 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 994 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 995 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 996 | struct weston_transform *transform; |
| 997 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 998 | if (is_focus_view(view)) { |
| 999 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1000 | transform = &fsurf->workspace_transform; |
| 1001 | } else { |
| 1002 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1003 | transform = &shsurf->workspace_transform; |
| 1004 | } |
| 1005 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1006 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1007 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1008 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1009 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1010 | weston_matrix_init(&transform->matrix); |
| 1011 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1012 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1013 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | static void |
| 1017 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1018 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1019 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1020 | unsigned int height; |
| 1021 | double d; |
| 1022 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1023 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1024 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1025 | d = height * fraction; |
| 1026 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1027 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | static void |
| 1032 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1033 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1034 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1035 | unsigned int height; |
| 1036 | double d; |
| 1037 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1038 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1039 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1040 | |
| 1041 | if (fraction > 0) |
| 1042 | d = -(height - height * fraction); |
| 1043 | else |
| 1044 | d = height + height * fraction; |
| 1045 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1046 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1051 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1052 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1053 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1054 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1055 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1056 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1057 | shell->workspaces.current, |
| 1058 | shell->workspaces.num); |
| 1059 | } |
| 1060 | |
| 1061 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1062 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1063 | unsigned int index, |
| 1064 | struct workspace *from, |
| 1065 | struct workspace *to) |
| 1066 | { |
| 1067 | shell->workspaces.current = index; |
| 1068 | |
| 1069 | shell->workspaces.anim_to = to; |
| 1070 | shell->workspaces.anim_from = from; |
| 1071 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1072 | shell->workspaces.anim_timestamp = 0; |
| 1073 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1074 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static void |
| 1078 | workspace_deactivate_transforms(struct workspace *ws) |
| 1079 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1080 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1081 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1082 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1083 | 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] | 1084 | if (is_focus_view(view)) { |
| 1085 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1086 | transform = &fsurf->workspace_transform; |
| 1087 | } else { |
| 1088 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1089 | transform = &shsurf->workspace_transform; |
| 1090 | } |
| 1091 | |
| 1092 | if (!wl_list_empty(&transform->link)) { |
| 1093 | wl_list_remove(&transform->link); |
| 1094 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1095 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1096 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | static void |
| 1101 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1102 | struct workspace *from, |
| 1103 | struct workspace *to) |
| 1104 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1105 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1106 | |
| 1107 | wl_list_remove(&shell->workspaces.animation.link); |
| 1108 | workspace_deactivate_transforms(from); |
| 1109 | workspace_deactivate_transforms(to); |
| 1110 | shell->workspaces.anim_to = NULL; |
| 1111 | |
| 1112 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1113 | } |
| 1114 | |
| 1115 | static void |
| 1116 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1117 | struct weston_output *output, uint32_t msecs) |
| 1118 | { |
| 1119 | struct desktop_shell *shell = |
| 1120 | container_of(animation, struct desktop_shell, |
| 1121 | workspaces.animation); |
| 1122 | struct workspace *from = shell->workspaces.anim_from; |
| 1123 | struct workspace *to = shell->workspaces.anim_to; |
| 1124 | uint32_t t; |
| 1125 | double x, y; |
| 1126 | |
| 1127 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1128 | finish_workspace_change_animation(shell, from, to); |
| 1129 | return; |
| 1130 | } |
| 1131 | |
| 1132 | if (shell->workspaces.anim_timestamp == 0) { |
| 1133 | if (shell->workspaces.anim_current == 0.0) |
| 1134 | shell->workspaces.anim_timestamp = msecs; |
| 1135 | else |
| 1136 | shell->workspaces.anim_timestamp = |
| 1137 | msecs - |
| 1138 | /* Invers of movement function 'y' below. */ |
| 1139 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1140 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1141 | M_2_PI); |
| 1142 | } |
| 1143 | |
| 1144 | t = msecs - shell->workspaces.anim_timestamp; |
| 1145 | |
| 1146 | /* |
| 1147 | * x = [0, π/2] |
| 1148 | * y(x) = sin(x) |
| 1149 | */ |
| 1150 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1151 | y = sin(x); |
| 1152 | |
| 1153 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1154 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1155 | |
| 1156 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1157 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1158 | shell->workspaces.anim_current = y; |
| 1159 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1160 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1161 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1162 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1163 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | static void |
| 1167 | animate_workspace_change(struct desktop_shell *shell, |
| 1168 | unsigned int index, |
| 1169 | struct workspace *from, |
| 1170 | struct workspace *to) |
| 1171 | { |
| 1172 | struct weston_output *output; |
| 1173 | |
| 1174 | int dir; |
| 1175 | |
| 1176 | if (index > shell->workspaces.current) |
| 1177 | dir = -1; |
| 1178 | else |
| 1179 | dir = 1; |
| 1180 | |
| 1181 | shell->workspaces.current = index; |
| 1182 | |
| 1183 | shell->workspaces.anim_dir = dir; |
| 1184 | shell->workspaces.anim_from = from; |
| 1185 | shell->workspaces.anim_to = to; |
| 1186 | shell->workspaces.anim_current = 0.0; |
| 1187 | shell->workspaces.anim_timestamp = 0; |
| 1188 | |
| 1189 | output = container_of(shell->compositor->output_list.next, |
| 1190 | struct weston_output, link); |
| 1191 | wl_list_insert(&output->animation_list, |
| 1192 | &shell->workspaces.animation.link); |
| 1193 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1194 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1195 | |
| 1196 | workspace_translate_in(to, 0); |
| 1197 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1198 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1199 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1200 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1201 | } |
| 1202 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1203 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1204 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1205 | struct workspace *from, struct workspace *to) |
| 1206 | { |
| 1207 | shell->workspaces.current = index; |
| 1208 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1209 | wl_list_remove(&from->layer.link); |
| 1210 | } |
| 1211 | |
| 1212 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1213 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1214 | { |
| 1215 | struct workspace *from; |
| 1216 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1217 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1218 | |
| 1219 | if (index == shell->workspaces.current) |
| 1220 | return; |
| 1221 | |
| 1222 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1223 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1224 | return; |
| 1225 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1226 | from = get_current_workspace(shell); |
| 1227 | to = get_workspace(shell, index); |
| 1228 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1229 | if (shell->workspaces.anim_from == to && |
| 1230 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1231 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1232 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1233 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1234 | return; |
| 1235 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1236 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1237 | if (shell->workspaces.anim_to != NULL) |
| 1238 | finish_workspace_change_animation(shell, |
| 1239 | shell->workspaces.anim_from, |
| 1240 | shell->workspaces.anim_to); |
| 1241 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1242 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1243 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1244 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1245 | wl_list_for_each(state, &from->focus_list, link) |
| 1246 | if (state->keyboard_focus) |
| 1247 | animate_focus_change(shell, from, |
| 1248 | get_default_view(state->keyboard_focus), NULL); |
| 1249 | |
| 1250 | wl_list_for_each(state, &to->focus_list, link) |
| 1251 | if (state->keyboard_focus) |
| 1252 | animate_focus_change(shell, to, |
| 1253 | NULL, get_default_view(state->keyboard_focus)); |
| 1254 | } |
| 1255 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1256 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1257 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1258 | else |
| 1259 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1260 | |
| 1261 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1262 | } |
| 1263 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1264 | static bool |
| 1265 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1266 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1267 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1268 | struct wl_list *e; |
| 1269 | |
| 1270 | if (wl_list_empty(list)) |
| 1271 | return false; |
| 1272 | |
| 1273 | e = list->next; |
| 1274 | |
| 1275 | if (e->next != list) |
| 1276 | return false; |
| 1277 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1278 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1282 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1283 | struct shell_surface *shsurf, |
| 1284 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1285 | { |
| 1286 | struct workspace *from; |
| 1287 | struct workspace *to; |
| 1288 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1289 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1290 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1291 | |
| 1292 | if (workspace == shell->workspaces.current) |
| 1293 | return; |
| 1294 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1295 | view = get_default_view(shsurf->surface); |
| 1296 | if (!view) |
| 1297 | return; |
| 1298 | |
| 1299 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1300 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1301 | if (workspace >= shell->workspaces.num) |
| 1302 | workspace = shell->workspaces.num - 1; |
| 1303 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1304 | from = get_current_workspace(shell); |
| 1305 | to = get_workspace(shell, workspace); |
| 1306 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1307 | wl_list_remove(&view->layer_link); |
| 1308 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1309 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1310 | shell_surface_update_child_surface_layers(shsurf); |
| 1311 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1312 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1313 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1314 | if (!seat->keyboard) |
| 1315 | continue; |
| 1316 | |
| 1317 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1318 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1319 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1320 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1321 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1322 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1326 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1327 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1328 | unsigned int index) |
| 1329 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1330 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1331 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1332 | struct shell_surface *shsurf; |
| 1333 | struct workspace *from; |
| 1334 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1335 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1336 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1337 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1338 | view = get_default_view(surface); |
| 1339 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1340 | index == shell->workspaces.current || |
| 1341 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1342 | return; |
| 1343 | |
| 1344 | from = get_current_workspace(shell); |
| 1345 | to = get_workspace(shell, index); |
| 1346 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1347 | wl_list_remove(&view->layer_link); |
| 1348 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1349 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1350 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1351 | if (shsurf != NULL) |
| 1352 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1353 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1354 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1355 | drop_focus_state(shell, from, surface); |
| 1356 | |
| 1357 | if (shell->workspaces.anim_from == to && |
| 1358 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1359 | wl_list_remove(&to->layer.link); |
| 1360 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1361 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1362 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1363 | broadcast_current_workspace_state(shell); |
| 1364 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1365 | return; |
| 1366 | } |
| 1367 | |
| 1368 | if (shell->workspaces.anim_to != NULL) |
| 1369 | finish_workspace_change_animation(shell, |
| 1370 | shell->workspaces.anim_from, |
| 1371 | shell->workspaces.anim_to); |
| 1372 | |
| 1373 | if (workspace_is_empty(from) && |
| 1374 | workspace_has_only(to, surface)) |
| 1375 | update_workspace(shell, index, from, to); |
| 1376 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1377 | if (shsurf != NULL && |
| 1378 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1379 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1380 | &shsurf->workspace_transform.link); |
| 1381 | |
| 1382 | animate_workspace_change(shell, index, from, to); |
| 1383 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1384 | |
| 1385 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1386 | |
| 1387 | state = ensure_focus_state(shell, seat); |
| 1388 | if (state != NULL) |
| 1389 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static void |
| 1393 | workspace_manager_move_surface(struct wl_client *client, |
| 1394 | struct wl_resource *resource, |
| 1395 | struct wl_resource *surface_resource, |
| 1396 | uint32_t workspace) |
| 1397 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1398 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1399 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1400 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1401 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1402 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1403 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1404 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1405 | shell_surface = get_shell_surface(main_surface); |
| 1406 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1407 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1408 | |
| 1409 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1413 | workspace_manager_move_surface, |
| 1414 | }; |
| 1415 | |
| 1416 | static void |
| 1417 | unbind_resource(struct wl_resource *resource) |
| 1418 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1419 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | static void |
| 1423 | bind_workspace_manager(struct wl_client *client, |
| 1424 | void *data, uint32_t version, uint32_t id) |
| 1425 | { |
| 1426 | struct desktop_shell *shell = data; |
| 1427 | struct wl_resource *resource; |
| 1428 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1429 | resource = wl_resource_create(client, |
| 1430 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1431 | |
| 1432 | if (resource == NULL) { |
| 1433 | weston_log("couldn't add workspace manager object"); |
| 1434 | return; |
| 1435 | } |
| 1436 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1437 | wl_resource_set_implementation(resource, |
| 1438 | &workspace_manager_implementation, |
| 1439 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1440 | wl_list_insert(&shell->workspaces.client_list, |
| 1441 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1442 | |
| 1443 | workspace_manager_send_state(resource, |
| 1444 | shell->workspaces.current, |
| 1445 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1446 | } |
| 1447 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1448 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1449 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1450 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1451 | { |
| 1452 | } |
| 1453 | |
| 1454 | static void |
| 1455 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1456 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1457 | struct weston_touch_move_grab *move = |
| 1458 | (struct weston_touch_move_grab *) container_of( |
| 1459 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1460 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1461 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1462 | shell_touch_grab_end(&move->base); |
| 1463 | free(move); |
| 1464 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | static void |
| 1468 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1469 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1470 | { |
| 1471 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1472 | struct shell_surface *shsurf = move->base.shsurf; |
| 1473 | struct weston_surface *es; |
| 1474 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1475 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1476 | |
| 1477 | if (!shsurf) |
| 1478 | return; |
| 1479 | |
| 1480 | es = shsurf->surface; |
| 1481 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 1482 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1483 | |
| 1484 | weston_compositor_schedule_repaint(es->compositor); |
| 1485 | } |
| 1486 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1487 | static void |
| 1488 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1489 | { |
| 1490 | struct weston_touch_move_grab *move = |
| 1491 | (struct weston_touch_move_grab *) container_of( |
| 1492 | grab, struct shell_touch_grab, grab); |
| 1493 | |
| 1494 | shell_touch_grab_end(&move->base); |
| 1495 | free(move); |
| 1496 | } |
| 1497 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1498 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1499 | touch_move_grab_down, |
| 1500 | touch_move_grab_up, |
| 1501 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1502 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1503 | }; |
| 1504 | |
| 1505 | static int |
| 1506 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1507 | { |
| 1508 | struct weston_touch_move_grab *move; |
| 1509 | |
| 1510 | if (!shsurf) |
| 1511 | return -1; |
| 1512 | |
| 1513 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1514 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1515 | if (shsurf->grabbed) |
| 1516 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1517 | |
| 1518 | move = malloc(sizeof *move); |
| 1519 | if (!move) |
| 1520 | return -1; |
| 1521 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1522 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1523 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1524 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1525 | seat->touch->grab_y; |
| 1526 | |
| 1527 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1528 | seat->touch); |
| 1529 | |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1534 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1535 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1539 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1540 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1541 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1542 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1543 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1544 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1545 | int dx, dy; |
| 1546 | |
| 1547 | weston_pointer_move(pointer, x, y); |
| 1548 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1549 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1550 | |
| 1551 | if (!shsurf) |
| 1552 | return; |
| 1553 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 1554 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1555 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1556 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1560 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1561 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1562 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1563 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1564 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1565 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1566 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1567 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1568 | if (pointer->button_count == 0 && |
| 1569 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1570 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1571 | free(grab); |
| 1572 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1573 | } |
| 1574 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1575 | static void |
| 1576 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1577 | { |
| 1578 | struct shell_grab *shell_grab = |
| 1579 | container_of(grab, struct shell_grab, grab); |
| 1580 | |
| 1581 | shell_grab_end(shell_grab); |
| 1582 | free(grab); |
| 1583 | } |
| 1584 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1585 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1586 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1587 | move_grab_motion, |
| 1588 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1589 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1590 | }; |
| 1591 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1592 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1593 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1594 | { |
| 1595 | struct weston_move_grab *move; |
| 1596 | |
| 1597 | if (!shsurf) |
| 1598 | return -1; |
| 1599 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1600 | if (shsurf->grabbed) |
| 1601 | return 0; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1602 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1603 | return 0; |
| 1604 | |
| 1605 | move = malloc(sizeof *move); |
| 1606 | if (!move) |
| 1607 | return -1; |
| 1608 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1609 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1610 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1611 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1612 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1613 | |
| 1614 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1615 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1616 | |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | static void |
| 1621 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1622 | struct wl_resource *seat_resource, uint32_t serial) |
| 1623 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1624 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1625 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1626 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1627 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1628 | if (seat->pointer && |
| 1629 | seat->pointer->button_count > 0 && |
| 1630 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1631 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1632 | if ((surface == shsurf->surface) && |
| 1633 | (surface_move(shsurf, seat) < 0)) |
| 1634 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1635 | } else if (seat->touch && |
| 1636 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1637 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1638 | if ((surface == shsurf->surface) && |
| 1639 | (surface_touch_move(shsurf, seat) < 0)) |
| 1640 | wl_resource_post_no_memory(resource); |
| 1641 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | struct weston_resize_grab { |
| 1645 | struct shell_grab base; |
| 1646 | uint32_t edges; |
| 1647 | int32_t width, height; |
| 1648 | }; |
| 1649 | |
| 1650 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1651 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1652 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1653 | { |
| 1654 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1655 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1656 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1657 | int32_t width, height; |
| 1658 | wl_fixed_t from_x, from_y; |
| 1659 | wl_fixed_t to_x, to_y; |
| 1660 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1661 | weston_pointer_move(pointer, x, y); |
| 1662 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1663 | if (!shsurf) |
| 1664 | return; |
| 1665 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1666 | weston_view_from_global_fixed(shsurf->view, |
| 1667 | pointer->grab_x, pointer->grab_y, |
| 1668 | &from_x, &from_y); |
| 1669 | weston_view_from_global_fixed(shsurf->view, |
| 1670 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1671 | |
| 1672 | width = resize->width; |
| 1673 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1674 | width += wl_fixed_to_int(from_x - to_x); |
| 1675 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1676 | width += wl_fixed_to_int(to_x - from_x); |
| 1677 | } |
| 1678 | |
| 1679 | height = resize->height; |
| 1680 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1681 | height += wl_fixed_to_int(from_y - to_y); |
| 1682 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1683 | height += wl_fixed_to_int(to_y - from_y); |
| 1684 | } |
| 1685 | |
| 1686 | shsurf->client->send_configure(shsurf->surface, |
| 1687 | resize->edges, width, height); |
| 1688 | } |
| 1689 | |
| 1690 | static void |
| 1691 | send_configure(struct weston_surface *surface, |
| 1692 | uint32_t edges, int32_t width, int32_t height) |
| 1693 | { |
| 1694 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1695 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1696 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1697 | edges, width, height); |
| 1698 | } |
| 1699 | |
| 1700 | static const struct weston_shell_client shell_client = { |
| 1701 | send_configure |
| 1702 | }; |
| 1703 | |
| 1704 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1705 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1706 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1707 | { |
| 1708 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1709 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1710 | enum wl_pointer_button_state state = state_w; |
| 1711 | |
| 1712 | if (pointer->button_count == 0 && |
| 1713 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1714 | shell_grab_end(&resize->base); |
| 1715 | free(grab); |
| 1716 | } |
| 1717 | } |
| 1718 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1719 | static void |
| 1720 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1721 | { |
| 1722 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1723 | |
| 1724 | shell_grab_end(&resize->base); |
| 1725 | free(grab); |
| 1726 | } |
| 1727 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1728 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1729 | noop_grab_focus, |
| 1730 | resize_grab_motion, |
| 1731 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1732 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1733 | }; |
| 1734 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1735 | /* |
| 1736 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1737 | * in the surface coordinates system. */ |
| 1738 | static void |
| 1739 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1740 | int32_t *y, int32_t *w, int32_t *h) { |
| 1741 | pixman_region32_t region; |
| 1742 | pixman_box32_t *box; |
| 1743 | struct weston_subsurface *subsurface; |
| 1744 | |
| 1745 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1746 | surface->width, |
| 1747 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1748 | |
| 1749 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1750 | pixman_region32_union_rect(®ion, ®ion, |
| 1751 | subsurface->position.x, |
| 1752 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1753 | subsurface->surface->width, |
| 1754 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | box = pixman_region32_extents(®ion); |
| 1758 | if (x) |
| 1759 | *x = box->x1; |
| 1760 | if (y) |
| 1761 | *y = box->y1; |
| 1762 | if (w) |
| 1763 | *w = box->x2 - box->x1; |
| 1764 | if (h) |
| 1765 | *h = box->y2 - box->y1; |
| 1766 | |
| 1767 | pixman_region32_fini(®ion); |
| 1768 | } |
| 1769 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1770 | static int |
| 1771 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1772 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1773 | { |
| 1774 | struct weston_resize_grab *resize; |
| 1775 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1776 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1777 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1778 | return 0; |
| 1779 | |
| 1780 | if (edges == 0 || edges > 15 || |
| 1781 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1782 | return 0; |
| 1783 | |
| 1784 | resize = malloc(sizeof *resize); |
| 1785 | if (!resize) |
| 1786 | return -1; |
| 1787 | |
| 1788 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1789 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1790 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1791 | |
| 1792 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1793 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1794 | |
| 1795 | return 0; |
| 1796 | } |
| 1797 | |
| 1798 | static void |
| 1799 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1800 | struct wl_resource *seat_resource, uint32_t serial, |
| 1801 | uint32_t edges) |
| 1802 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1803 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1804 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1805 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1806 | |
| 1807 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1808 | return; |
| 1809 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1810 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1811 | if (seat->pointer->button_count == 0 || |
| 1812 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1813 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1814 | return; |
| 1815 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1816 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1817 | wl_resource_post_no_memory(resource); |
| 1818 | } |
| 1819 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1820 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1821 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1822 | |
| 1823 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1824 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1825 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1826 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1827 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1828 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1829 | wl_fixed_t sx, sy; |
| 1830 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1831 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1832 | pointer->x, pointer->y, |
| 1833 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1834 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1835 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1836 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1840 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1841 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1842 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1843 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1844 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1845 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1846 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1847 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1848 | uint32_t time, uint32_t button, uint32_t state) |
| 1849 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1850 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1851 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1852 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1853 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1854 | if (shsurf && button == BTN_LEFT && state) { |
| 1855 | activate(shsurf->shell, shsurf->surface, seat); |
| 1856 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1857 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1858 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1859 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1860 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1861 | } |
| 1862 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1863 | static void |
| 1864 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1865 | { |
| 1866 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1867 | |
| 1868 | shell_grab_end(grab); |
| 1869 | free(grab); |
| 1870 | } |
| 1871 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1872 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1873 | busy_cursor_grab_focus, |
| 1874 | busy_cursor_grab_motion, |
| 1875 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1876 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1877 | }; |
| 1878 | |
| 1879 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1880 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1881 | { |
| 1882 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1883 | |
| 1884 | grab = malloc(sizeof *grab); |
| 1885 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1886 | return; |
| 1887 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1888 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1889 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1890 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1891 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1892 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1893 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1894 | { |
| 1895 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1896 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1897 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1898 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1899 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1900 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1901 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1902 | } |
| 1903 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1904 | static void |
| 1905 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1906 | { |
| 1907 | if (!shsurf || !shsurf->ping_timer) |
| 1908 | return; |
| 1909 | |
| 1910 | if (shsurf->ping_timer->source) |
| 1911 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1912 | |
| 1913 | free(shsurf->ping_timer); |
| 1914 | shsurf->ping_timer = NULL; |
| 1915 | } |
| 1916 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1917 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1918 | ping_timeout_handler(void *data) |
| 1919 | { |
| 1920 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1921 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1922 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1923 | /* Client is not responding */ |
| 1924 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1925 | |
| 1926 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1927 | if (seat->pointer->focus && |
| 1928 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1929 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1930 | |
| 1931 | return 1; |
| 1932 | } |
| 1933 | |
| 1934 | static void |
| 1935 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1936 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1937 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1938 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1939 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1940 | |
| 1941 | if (!shsurf) |
| 1942 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1943 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1944 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1945 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1946 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1947 | return; |
| 1948 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1949 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1950 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1951 | if (!shsurf->ping_timer) |
| 1952 | return; |
| 1953 | |
| 1954 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1955 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1956 | shsurf->ping_timer->source = |
| 1957 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1958 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1959 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1960 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1965 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1966 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1967 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1968 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1969 | struct weston_compositor *compositor; |
| 1970 | struct shell_surface *shsurf; |
| 1971 | uint32_t serial; |
| 1972 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1973 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1974 | return; |
| 1975 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1976 | compositor = view->surface->compositor; |
| 1977 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1978 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1979 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1980 | set_busy_cursor(shsurf, pointer); |
| 1981 | } else { |
| 1982 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1983 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1988 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1989 | { |
| 1990 | struct wl_listener *listener; |
| 1991 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1992 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1993 | return; |
| 1994 | |
| 1995 | listener = malloc(sizeof *listener); |
| 1996 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1997 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2001 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 2002 | uint32_t serial) |
| 2003 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2004 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2005 | struct weston_seat *seat; |
| 2006 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2007 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 2008 | if (shsurf->ping_timer == NULL) |
| 2009 | /* Just ignore unsolicited pong. */ |
| 2010 | return; |
| 2011 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2012 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2013 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 2014 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 2015 | if(seat->pointer) |
| 2016 | end_busy_cursor(shsurf, seat->pointer); |
| 2017 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2018 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2019 | } |
| 2020 | } |
| 2021 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2022 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2023 | set_title(struct shell_surface *shsurf, const char *title) |
| 2024 | { |
| 2025 | free(shsurf->title); |
| 2026 | shsurf->title = strdup(title); |
| 2027 | } |
| 2028 | |
| 2029 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2030 | shell_surface_set_title(struct wl_client *client, |
| 2031 | struct wl_resource *resource, const char *title) |
| 2032 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2033 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2034 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2035 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | static void |
| 2039 | shell_surface_set_class(struct wl_client *client, |
| 2040 | struct wl_resource *resource, const char *class) |
| 2041 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2042 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2043 | |
| 2044 | free(shsurf->class); |
| 2045 | shsurf->class = strdup(class); |
| 2046 | } |
| 2047 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2048 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2049 | restore_output_mode(struct weston_output *output) |
| 2050 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2051 | if (output->current_mode != output->original_mode || |
| 2052 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2053 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2054 | output->original_mode, |
| 2055 | output->original_scale, |
| 2056 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | static void |
| 2060 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2061 | { |
| 2062 | struct weston_output *output; |
| 2063 | |
| 2064 | wl_list_for_each(output, &compositor->output_list, link) |
| 2065 | restore_output_mode(output); |
| 2066 | } |
| 2067 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2068 | static int |
| 2069 | get_output_panel_height(struct desktop_shell *shell, |
| 2070 | struct weston_output *output) |
| 2071 | { |
| 2072 | struct weston_view *view; |
| 2073 | int panel_height = 0; |
| 2074 | |
| 2075 | if (!output) |
| 2076 | return 0; |
| 2077 | |
| 2078 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2079 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 2080 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2081 | break; |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | return panel_height; |
| 2086 | } |
| 2087 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2088 | /* The surface will be inserted into the list immediately after the link |
| 2089 | * returned by this function (i.e. will be stacked immediately above the |
| 2090 | * returned link). */ |
| 2091 | static struct wl_list * |
| 2092 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2093 | { |
| 2094 | struct workspace *ws; |
| 2095 | |
| 2096 | switch (shsurf->type) { |
Philip Withnall | da704d9 | 2013-11-25 18:01:46 +0000 | [diff] [blame] | 2097 | case SHELL_SURFACE_POPUP: { |
| 2098 | /* Popups should go at the front of the workspace of their |
| 2099 | * parent surface, rather than just in front of the parent. This |
| 2100 | * fixes the situation where there are two top-level windows: |
| 2101 | * - Above |
| 2102 | * - Below |
| 2103 | * and a pop-up menu is created for 'Below'. We want: |
| 2104 | * - Popup |
| 2105 | * - Above |
| 2106 | * - Below |
| 2107 | * not: |
| 2108 | * - Above |
| 2109 | * - Popup |
| 2110 | * - Below |
| 2111 | */ |
| 2112 | struct shell_surface *parent_shsurf; |
| 2113 | |
| 2114 | parent_shsurf = get_shell_surface(shsurf->parent); |
| 2115 | if (parent_shsurf != NULL) |
| 2116 | return shell_surface_calculate_layer_link(parent_shsurf); |
| 2117 | |
| 2118 | break; |
| 2119 | } |
| 2120 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2121 | case SHELL_SURFACE_TRANSIENT: { |
| 2122 | /* Move the surface to its parent layer so that surfaces which |
| 2123 | * are transient for fullscreen surfaces don't get hidden by the |
Philip Withnall | da704d9 | 2013-11-25 18:01:46 +0000 | [diff] [blame] | 2124 | * fullscreen surfaces. However, unlike popups, transient |
| 2125 | * surfaces are stacked in front of their parent but not in |
| 2126 | * front of other surfaces of the same type. */ |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2127 | struct weston_view *parent; |
| 2128 | |
| 2129 | /* TODO: Handle a parent with multiple views */ |
| 2130 | parent = get_default_view(shsurf->parent); |
| 2131 | if (parent) |
| 2132 | return parent->layer_link.prev; |
| 2133 | |
| 2134 | break; |
| 2135 | } |
| 2136 | |
| 2137 | case SHELL_SURFACE_FULLSCREEN: |
| 2138 | return &shsurf->shell->fullscreen_layer.view_list; |
| 2139 | |
| 2140 | case SHELL_SURFACE_XWAYLAND: |
| 2141 | case SHELL_SURFACE_TOPLEVEL: |
| 2142 | case SHELL_SURFACE_MAXIMIZED: |
| 2143 | case SHELL_SURFACE_NONE: |
| 2144 | default: |
| 2145 | /* Go to the fallback, below. */ |
| 2146 | break; |
| 2147 | } |
| 2148 | |
| 2149 | /* Move the surface to a normal workspace layer so that surfaces |
| 2150 | * which were previously fullscreen or transient are no longer |
| 2151 | * rendered on top. */ |
| 2152 | ws = get_current_workspace(shsurf->shell); |
| 2153 | return &ws->layer.view_list; |
| 2154 | } |
| 2155 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2156 | static void |
| 2157 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2158 | { |
| 2159 | struct shell_surface *child; |
| 2160 | |
| 2161 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2162 | * stacked above shsurf. */ |
| 2163 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2164 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2165 | weston_view_geometry_dirty(child->view); |
| 2166 | wl_list_remove(&child->view->layer_link); |
| 2167 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2168 | &child->view->layer_link); |
| 2169 | weston_view_geometry_dirty(child->view); |
| 2170 | weston_surface_damage(child->surface); |
| 2171 | |
| 2172 | /* Recurse. We don’t expect this to recurse very far (if |
| 2173 | * at all) because that would imply we have transient |
| 2174 | * (or popup) children of transient surfaces, which |
| 2175 | * would be unusual. */ |
| 2176 | shell_surface_update_child_surface_layers(child); |
| 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2181 | /* Update the surface’s layer. Mark both the old and new views as having dirty |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2182 | * geometry to ensure the changes are redrawn. |
| 2183 | * |
| 2184 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2185 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2186 | static void |
| 2187 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2188 | { |
| 2189 | struct wl_list *new_layer_link; |
| 2190 | |
| 2191 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2192 | |
| 2193 | if (new_layer_link == &shsurf->view->layer_link) |
| 2194 | return; |
| 2195 | |
| 2196 | weston_view_geometry_dirty(shsurf->view); |
| 2197 | wl_list_remove(&shsurf->view->layer_link); |
| 2198 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2199 | weston_view_geometry_dirty(shsurf->view); |
| 2200 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2201 | |
| 2202 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2203 | } |
| 2204 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2205 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2206 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2207 | struct weston_surface *parent) |
| 2208 | { |
| 2209 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2210 | |
| 2211 | wl_list_remove(&shsurf->children_link); |
| 2212 | wl_list_init(&shsurf->children_link); |
| 2213 | |
| 2214 | /* Insert into the parent surface’s child list. */ |
| 2215 | if (parent != NULL) { |
| 2216 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2217 | if (parent_shsurf != NULL) |
| 2218 | wl_list_insert(&parent_shsurf->children_list, |
| 2219 | &shsurf->children_link); |
| 2220 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2224 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2225 | struct weston_output *output) |
| 2226 | { |
| 2227 | struct weston_surface *es = shsurf->surface; |
| 2228 | |
| 2229 | /* get the default output, if the client set it as NULL |
| 2230 | check whether the ouput is available */ |
| 2231 | if (output) |
| 2232 | shsurf->output = output; |
| 2233 | else if (es->output) |
| 2234 | shsurf->output = es->output; |
| 2235 | else |
| 2236 | shsurf->output = get_default_output(es->compositor); |
| 2237 | } |
| 2238 | |
| 2239 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2240 | set_toplevel(struct shell_surface *shsurf) |
| 2241 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2242 | shell_surface_set_parent(shsurf, NULL); |
| 2243 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2244 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2245 | |
| 2246 | /* The layer_link is updated in set_surface_type(), |
| 2247 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | static void |
| 2251 | shell_surface_set_toplevel(struct wl_client *client, |
| 2252 | struct wl_resource *resource) |
| 2253 | { |
| 2254 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2255 | |
| 2256 | set_toplevel(surface); |
| 2257 | } |
| 2258 | |
| 2259 | static void |
| 2260 | set_transient(struct shell_surface *shsurf, |
| 2261 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2262 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2263 | assert(parent != NULL); |
| 2264 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2265 | shsurf->transient.x = x; |
| 2266 | shsurf->transient.y = y; |
| 2267 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2268 | |
| 2269 | shell_surface_set_parent(shsurf, parent); |
| 2270 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2271 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2272 | |
| 2273 | /* The layer_link is updated in set_surface_type(), |
| 2274 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | static void |
| 2278 | shell_surface_set_transient(struct wl_client *client, |
| 2279 | struct wl_resource *resource, |
| 2280 | struct wl_resource *parent_resource, |
| 2281 | int x, int y, uint32_t flags) |
| 2282 | { |
| 2283 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2284 | struct weston_surface *parent = |
| 2285 | wl_resource_get_user_data(parent_resource); |
| 2286 | |
| 2287 | set_transient(shsurf, parent, x, y, flags); |
| 2288 | } |
| 2289 | |
| 2290 | static void |
| 2291 | set_fullscreen(struct shell_surface *shsurf, |
| 2292 | uint32_t method, |
| 2293 | uint32_t framerate, |
| 2294 | struct weston_output *output) |
| 2295 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2296 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2297 | |
| 2298 | shsurf->fullscreen_output = shsurf->output; |
| 2299 | shsurf->fullscreen.type = method; |
| 2300 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2301 | |
| 2302 | shell_surface_set_parent(shsurf, NULL); |
| 2303 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2304 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
| 2305 | |
| 2306 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2307 | shsurf->output->width, |
| 2308 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2309 | |
| 2310 | /* The layer_link is updated in set_surface_type(), |
| 2311 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | static void |
| 2315 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2316 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2317 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2318 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2319 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2320 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2321 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2322 | shsurf->fullscreen_output = NULL; |
| 2323 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2324 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2325 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2326 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2327 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2328 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2329 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2330 | if (shsurf->fullscreen.black_view) |
| 2331 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2332 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2333 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2334 | weston_view_set_position(shsurf->view, |
| 2335 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2336 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2337 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2338 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2339 | shsurf->saved_rotation_valid = false; |
| 2340 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2341 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2342 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2343 | } |
| 2344 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2345 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2346 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2347 | struct wl_resource *resource, |
| 2348 | uint32_t method, |
| 2349 | uint32_t framerate, |
| 2350 | struct wl_resource *output_resource) |
| 2351 | { |
| 2352 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2353 | struct weston_output *output; |
| 2354 | |
| 2355 | if (output_resource) |
| 2356 | output = wl_resource_get_user_data(output_resource); |
| 2357 | else |
| 2358 | output = NULL; |
| 2359 | |
| 2360 | set_fullscreen(shsurf, method, framerate, output); |
| 2361 | } |
| 2362 | |
| 2363 | static void |
| 2364 | set_popup(struct shell_surface *shsurf, |
| 2365 | struct weston_surface *parent, |
| 2366 | struct weston_seat *seat, |
| 2367 | uint32_t serial, |
| 2368 | int32_t x, |
| 2369 | int32_t y) |
| 2370 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2371 | assert(parent != NULL); |
| 2372 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2373 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2374 | shsurf->popup.serial = serial; |
| 2375 | shsurf->popup.x = x; |
| 2376 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2377 | |
| 2378 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | b995e1d | 2013-11-25 18:01:39 +0000 | [diff] [blame] | 2379 | |
| 2380 | shsurf->next_type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | static void |
| 2384 | shell_surface_set_popup(struct wl_client *client, |
| 2385 | struct wl_resource *resource, |
| 2386 | struct wl_resource *seat_resource, |
| 2387 | uint32_t serial, |
| 2388 | struct wl_resource *parent_resource, |
| 2389 | int32_t x, int32_t y, uint32_t flags) |
| 2390 | { |
| 2391 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2392 | |
| 2393 | set_popup(shsurf, |
| 2394 | wl_resource_get_user_data(parent_resource), |
| 2395 | wl_resource_get_user_data(seat_resource), |
| 2396 | serial, x, y); |
| 2397 | } |
| 2398 | |
| 2399 | static void |
| 2400 | set_maximized(struct shell_surface *shsurf, |
| 2401 | struct weston_output *output) |
| 2402 | { |
| 2403 | struct desktop_shell *shell; |
| 2404 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2405 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2406 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2407 | |
| 2408 | shell = shell_surface_get_shell(shsurf); |
| 2409 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2410 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2411 | |
| 2412 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2413 | shsurf->output->width, |
| 2414 | shsurf->output->height - panel_height); |
| 2415 | |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2416 | shell_surface_set_parent(shsurf, NULL); |
| 2417 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2418 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
| 2419 | } |
| 2420 | |
| 2421 | static void |
| 2422 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2423 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2424 | /* undo all maximized things here */ |
| 2425 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2426 | weston_view_set_position(shsurf->view, |
| 2427 | shsurf->saved_x, |
| 2428 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2429 | |
| 2430 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2431 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2432 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2433 | shsurf->saved_rotation_valid = false; |
| 2434 | } |
| 2435 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2436 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2437 | } |
| 2438 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2439 | static void |
| 2440 | shell_surface_set_maximized(struct wl_client *client, |
| 2441 | struct wl_resource *resource, |
| 2442 | struct wl_resource *output_resource) |
| 2443 | { |
| 2444 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2445 | struct weston_output *output; |
| 2446 | |
| 2447 | if (output_resource) |
| 2448 | output = wl_resource_get_user_data(output_resource); |
| 2449 | else |
| 2450 | output = NULL; |
| 2451 | |
| 2452 | set_maximized(shsurf, output); |
| 2453 | } |
| 2454 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2455 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2456 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2457 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2458 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2459 | { |
| 2460 | switch (surface->type) { |
| 2461 | case SHELL_SURFACE_FULLSCREEN: |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2462 | unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2463 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2464 | case SHELL_SURFACE_MAXIMIZED: |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2465 | unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2466 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2467 | case SHELL_SURFACE_NONE: |
| 2468 | case SHELL_SURFACE_TOPLEVEL: |
| 2469 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2470 | case SHELL_SURFACE_POPUP: |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2471 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2472 | default: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2473 | break; |
| 2474 | } |
| 2475 | |
| 2476 | surface->type = SHELL_SURFACE_NONE; |
| 2477 | return 0; |
| 2478 | } |
| 2479 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2480 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2481 | set_surface_type(struct shell_surface *shsurf) |
| 2482 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2483 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2484 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2485 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2486 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2487 | |
| 2488 | shsurf->type = shsurf->next_type; |
| 2489 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 2490 | |
| 2491 | switch (shsurf->type) { |
| 2492 | case SHELL_SURFACE_TOPLEVEL: |
| 2493 | break; |
| 2494 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2495 | if (pev) |
| 2496 | weston_view_set_position(shsurf->view, |
| 2497 | pev->geometry.x + shsurf->transient.x, |
| 2498 | pev->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2499 | break; |
| 2500 | |
| 2501 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2502 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2503 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2504 | shsurf->saved_y = shsurf->view->geometry.y; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2505 | shsurf->saved_position_valid = true; |
| 2506 | |
| 2507 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2508 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2509 | wl_list_init(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2510 | weston_view_geometry_dirty(shsurf->view); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2511 | shsurf->saved_rotation_valid = true; |
| 2512 | } |
| 2513 | break; |
| 2514 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2515 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2516 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2517 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2518 | break; |
| 2519 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2520 | case SHELL_SURFACE_POPUP: |
| 2521 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2522 | default: |
| 2523 | break; |
| 2524 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2525 | |
| 2526 | /* Update the surface’s layer. */ |
| 2527 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2528 | } |
| 2529 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2530 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2531 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2532 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2533 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2534 | } |
| 2535 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2536 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 2537 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy); |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2538 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2539 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2540 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2541 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2542 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2543 | { |
| 2544 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2545 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2546 | |
| 2547 | surface = weston_surface_create(ec); |
| 2548 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2549 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2550 | return NULL; |
| 2551 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2552 | view = weston_view_create(surface); |
| 2553 | if (surface == NULL) { |
| 2554 | weston_log("no memory\n"); |
| 2555 | weston_surface_destroy(surface); |
| 2556 | return NULL; |
| 2557 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2558 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2559 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2560 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2561 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2562 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2563 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2564 | pixman_region32_fini(&surface->input); |
| 2565 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 2566 | |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2567 | surface->width = w; |
| 2568 | surface->height = h; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 2569 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2570 | |
| 2571 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2572 | } |
| 2573 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2574 | static void |
| 2575 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2576 | { |
| 2577 | struct weston_output *output = shsurf->fullscreen_output; |
| 2578 | |
| 2579 | assert(shsurf->type == SHELL_SURFACE_FULLSCREEN); |
| 2580 | |
| 2581 | if (!shsurf->fullscreen.black_view) |
| 2582 | shsurf->fullscreen.black_view = |
| 2583 | create_black_surface(shsurf->surface->compositor, |
| 2584 | shsurf->surface, |
| 2585 | output->x, output->y, |
| 2586 | output->width, |
| 2587 | output->height); |
| 2588 | |
| 2589 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2590 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2591 | wl_list_insert(&shsurf->view->layer_link, |
| 2592 | &shsurf->fullscreen.black_view->layer_link); |
| 2593 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2594 | weston_surface_damage(shsurf->surface); |
| 2595 | } |
| 2596 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2597 | /* Create black surface and append it to the associated fullscreen surface. |
| 2598 | * Handle size dismatch and positioning according to the method. */ |
| 2599 | static void |
| 2600 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2601 | { |
| 2602 | struct weston_output *output = shsurf->fullscreen_output; |
| 2603 | struct weston_surface *surface = shsurf->surface; |
| 2604 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2605 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2606 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2607 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2608 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2609 | restore_output_mode(output); |
| 2610 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2611 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2612 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2613 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2614 | &surf_width, &surf_height); |
| 2615 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2616 | switch (shsurf->fullscreen.type) { |
| 2617 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2618 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2619 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2620 | break; |
| 2621 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2622 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2623 | if (output->width == surf_width && |
| 2624 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2625 | weston_view_set_position(shsurf->view, |
| 2626 | output->x - surf_x, |
| 2627 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | } |
| 2630 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2631 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2632 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2633 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2634 | output_aspect = (float) output->width / |
| 2635 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2636 | /* XXX: Use surf_width and surf_height here? */ |
| 2637 | surface_aspect = (float) surface->width / |
| 2638 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2639 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2640 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2641 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2642 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2643 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2644 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2645 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2646 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2647 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2648 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2649 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2650 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2651 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2652 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2653 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2654 | break; |
| 2655 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2656 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2657 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2658 | surf_width * surface->buffer_viewport.scale, |
| 2659 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2660 | shsurf->fullscreen.framerate}; |
| 2661 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2662 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2663 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2664 | weston_view_set_position(shsurf->view, |
| 2665 | output->x - surf_x, |
| 2666 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 2667 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2668 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2669 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2670 | output->x - surf_x, |
| 2671 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2672 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2673 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2674 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2675 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2676 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2677 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2678 | break; |
| 2679 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2680 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2681 | break; |
| 2682 | default: |
| 2683 | break; |
| 2684 | } |
| 2685 | } |
| 2686 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2687 | static void |
| 2688 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2689 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2690 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2691 | } |
| 2692 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2693 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2694 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2695 | { |
| 2696 | /* XXX: using the same fields for transient type */ |
| 2697 | shsurf->transient.x = x; |
| 2698 | shsurf->transient.y = y; |
| 2699 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2700 | |
| 2701 | shell_surface_set_parent(shsurf, NULL); |
| 2702 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2703 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2704 | } |
| 2705 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2706 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2707 | |
| 2708 | static void |
| 2709 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2710 | { |
| 2711 | struct shell_seat *shseat = |
| 2712 | container_of(listener, |
| 2713 | struct shell_seat, seat_destroy_listener); |
| 2714 | struct shell_surface *shsurf, *prev = NULL; |
| 2715 | |
| 2716 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2717 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2718 | shseat->popup_grab.client = NULL; |
| 2719 | |
| 2720 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2721 | shsurf->popup.shseat = NULL; |
| 2722 | if (prev) { |
| 2723 | wl_list_init(&prev->popup.grab_link); |
| 2724 | } |
| 2725 | prev = shsurf; |
| 2726 | } |
| 2727 | wl_list_init(&prev->popup.grab_link); |
| 2728 | } |
| 2729 | |
| 2730 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2731 | free(shseat); |
| 2732 | } |
| 2733 | |
| 2734 | static struct shell_seat * |
| 2735 | create_shell_seat(struct weston_seat *seat) |
| 2736 | { |
| 2737 | struct shell_seat *shseat; |
| 2738 | |
| 2739 | shseat = calloc(1, sizeof *shseat); |
| 2740 | if (!shseat) { |
| 2741 | weston_log("no memory to allocate shell seat\n"); |
| 2742 | return NULL; |
| 2743 | } |
| 2744 | |
| 2745 | shseat->seat = seat; |
| 2746 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2747 | |
| 2748 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2749 | wl_signal_add(&seat->destroy_signal, |
| 2750 | &shseat->seat_destroy_listener); |
| 2751 | |
| 2752 | return shseat; |
| 2753 | } |
| 2754 | |
| 2755 | static struct shell_seat * |
| 2756 | get_shell_seat(struct weston_seat *seat) |
| 2757 | { |
| 2758 | struct wl_listener *listener; |
| 2759 | |
| 2760 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2761 | if (listener == NULL) |
| 2762 | return create_shell_seat(seat); |
| 2763 | |
| 2764 | return container_of(listener, |
| 2765 | struct shell_seat, seat_destroy_listener); |
| 2766 | } |
| 2767 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2768 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2769 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2770 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2771 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2772 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2773 | struct shell_seat *shseat = |
| 2774 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2775 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2776 | wl_fixed_t sx, sy; |
| 2777 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2778 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2779 | pointer->x, pointer->y, |
| 2780 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2781 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2782 | if (view && view->surface->resource && |
| 2783 | wl_resource_get_client(view->surface->resource) == client) { |
| 2784 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2785 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2786 | weston_pointer_set_focus(pointer, NULL, |
| 2787 | wl_fixed_from_int(0), |
| 2788 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2793 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2794 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2795 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2796 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2797 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2798 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2799 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2800 | weston_pointer_move(pointer, x, y); |
| 2801 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2802 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2803 | weston_view_from_global_fixed(pointer->focus, |
| 2804 | pointer->x, pointer->y, |
| 2805 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2806 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2807 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2811 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2812 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2813 | { |
| 2814 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2815 | struct shell_seat *shseat = |
| 2816 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2817 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2818 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2819 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2820 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2821 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2822 | resource_list = &grab->pointer->focus_resource_list; |
| 2823 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2824 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2825 | wl_resource_for_each(resource, resource_list) { |
| 2826 | wl_pointer_send_button(resource, serial, |
| 2827 | time, button, state); |
| 2828 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2829 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2830 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2831 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2832 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2833 | } |
| 2834 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2835 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2836 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2837 | } |
| 2838 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2839 | static void |
| 2840 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2841 | { |
| 2842 | popup_grab_end(grab->pointer); |
| 2843 | } |
| 2844 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2845 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2846 | popup_grab_focus, |
| 2847 | popup_grab_motion, |
| 2848 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2849 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2850 | }; |
| 2851 | |
| 2852 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2853 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2854 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2855 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2856 | struct shell_seat *shseat = |
| 2857 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2858 | struct shell_surface *shsurf; |
| 2859 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2860 | |
| 2861 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2862 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2863 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2864 | shseat->popup_grab.grab.interface = NULL; |
| 2865 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2866 | /* Send the popup_done event to all the popups open */ |
| 2867 | 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] | 2868 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2869 | shsurf->popup.shseat = NULL; |
| 2870 | if (prev) { |
| 2871 | wl_list_init(&prev->popup.grab_link); |
| 2872 | } |
| 2873 | prev = shsurf; |
| 2874 | } |
| 2875 | wl_list_init(&prev->popup.grab_link); |
| 2876 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | static void |
| 2881 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2882 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2883 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2884 | |
| 2885 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2886 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2887 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2888 | /* We must make sure here that this popup was opened after |
| 2889 | * a mouse press, and not just by moving around with other |
| 2890 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2891 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2892 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2893 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2894 | 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] | 2895 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2896 | } else { |
| 2897 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2898 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | static void |
| 2902 | remove_popup_grab(struct shell_surface *shsurf) |
| 2903 | { |
| 2904 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2905 | |
| 2906 | wl_list_remove(&shsurf->popup.grab_link); |
| 2907 | wl_list_init(&shsurf->popup.grab_link); |
| 2908 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2909 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2910 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2915 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2916 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2917 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2918 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2919 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2920 | shsurf->surface->output = parent_view->output; |
| 2921 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2922 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2923 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2924 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2925 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2926 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2927 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2928 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2929 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2930 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2931 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2932 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2933 | } |
| 2934 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2935 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2936 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2937 | shell_surface_move, |
| 2938 | shell_surface_resize, |
| 2939 | shell_surface_set_toplevel, |
| 2940 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2941 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2942 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2943 | shell_surface_set_maximized, |
| 2944 | shell_surface_set_title, |
| 2945 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2946 | }; |
| 2947 | |
| 2948 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2949 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2950 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2951 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2952 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2953 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2954 | remove_popup_grab(shsurf); |
| 2955 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2956 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2957 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2958 | shell_surface_is_top_fullscreen(shsurf)) |
| 2959 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2960 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2961 | if (shsurf->fullscreen.black_view) |
| 2962 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2963 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2964 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2965 | * we can always remove the listener. |
| 2966 | */ |
| 2967 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2968 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2969 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2970 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2971 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2972 | weston_view_destroy(shsurf->view); |
| 2973 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2974 | wl_list_remove(&shsurf->children_link); |
| 2975 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2976 | wl_list_remove(&shsurf->link); |
| 2977 | free(shsurf); |
| 2978 | } |
| 2979 | |
| 2980 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2981 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2982 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2983 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2984 | |
| 2985 | destroy_shell_surface(shsurf); |
| 2986 | } |
| 2987 | |
| 2988 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2989 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2990 | { |
| 2991 | struct shell_surface *shsurf = container_of(listener, |
| 2992 | struct shell_surface, |
| 2993 | surface_destroy_listener); |
| 2994 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2995 | if (shsurf->resource) |
| 2996 | wl_resource_destroy(shsurf->resource); |
| 2997 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2998 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2999 | } |
| 3000 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3001 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3002 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3003 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3004 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3005 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3006 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3007 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3008 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3009 | else |
| 3010 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3011 | } |
| 3012 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3013 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3014 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3015 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3016 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3017 | struct shell_surface *shsurf; |
| 3018 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3019 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3020 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3021 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3022 | } |
| 3023 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3024 | shsurf = calloc(1, sizeof *shsurf); |
| 3025 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3026 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3027 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3028 | } |
| 3029 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3030 | shsurf->view = weston_view_create(surface); |
| 3031 | if (!shsurf->view) { |
| 3032 | weston_log("no memory to allocate shell surface\n"); |
| 3033 | free(shsurf); |
| 3034 | return NULL; |
| 3035 | } |
| 3036 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3037 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3038 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3039 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3040 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3041 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3042 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3043 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3044 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3045 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3046 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3047 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3048 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3049 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3050 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3051 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3052 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3053 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3054 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3055 | |
| 3056 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3057 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3058 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3059 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3060 | /* empty when not in use */ |
| 3061 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3062 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3063 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3064 | wl_list_init(&shsurf->workspace_transform.link); |
| 3065 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3066 | wl_list_init(&shsurf->children_link); |
| 3067 | wl_list_init(&shsurf->children_list); |
| 3068 | shsurf->parent = NULL; |
| 3069 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3070 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3071 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3072 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3073 | shsurf->client = client; |
| 3074 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3075 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3076 | } |
| 3077 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3078 | static struct weston_view * |
| 3079 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3080 | { |
| 3081 | return shsurf->view; |
| 3082 | } |
| 3083 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3084 | static void |
| 3085 | shell_get_shell_surface(struct wl_client *client, |
| 3086 | struct wl_resource *resource, |
| 3087 | uint32_t id, |
| 3088 | struct wl_resource *surface_resource) |
| 3089 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3090 | struct weston_surface *surface = |
| 3091 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3092 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3093 | struct shell_surface *shsurf; |
| 3094 | |
| 3095 | if (get_shell_surface(surface)) { |
| 3096 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3097 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3098 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3099 | return; |
| 3100 | } |
| 3101 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3102 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3103 | if (!shsurf) { |
| 3104 | wl_resource_post_error(surface_resource, |
| 3105 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3106 | "surface->configure already set"); |
| 3107 | return; |
| 3108 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3109 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3110 | shsurf->resource = |
| 3111 | wl_resource_create(client, |
| 3112 | &wl_shell_surface_interface, 1, id); |
| 3113 | wl_resource_set_implementation(shsurf->resource, |
| 3114 | &shell_surface_implementation, |
| 3115 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3119 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3120 | }; |
| 3121 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3122 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3123 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3124 | |
| 3125 | static int |
| 3126 | screensaver_timeout(void *data) |
| 3127 | { |
| 3128 | struct desktop_shell *shell = data; |
| 3129 | |
| 3130 | shell_fade(shell, FADE_OUT); |
| 3131 | |
| 3132 | return 1; |
| 3133 | } |
| 3134 | |
| 3135 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3136 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3137 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3138 | struct desktop_shell *shell = |
| 3139 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3140 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3141 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3142 | |
| 3143 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3144 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3148 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3149 | { |
| 3150 | if (shell->screensaver.binding) |
| 3151 | return; |
| 3152 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3153 | if (!shell->screensaver.path) { |
| 3154 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3155 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3156 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3157 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3158 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3159 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3160 | return; |
| 3161 | } |
| 3162 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3163 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3164 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3165 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3166 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3170 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3171 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3172 | if (shell->screensaver.process.pid == 0) |
| 3173 | return; |
| 3174 | |
| 3175 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3179 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3180 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3181 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3182 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3183 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3184 | if (v->output == ev->output && v != ev) { |
| 3185 | weston_view_unmap(v); |
| 3186 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3190 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3191 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3192 | if (wl_list_empty(&ev->layer_link)) { |
| 3193 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3194 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3199 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3200 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3201 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3202 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3203 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3204 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3205 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3206 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3210 | desktop_shell_set_background(struct wl_client *client, |
| 3211 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3212 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3213 | struct wl_resource *surface_resource) |
| 3214 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3215 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3216 | struct weston_surface *surface = |
| 3217 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3218 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3219 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3220 | if (surface->configure) { |
| 3221 | wl_resource_post_error(surface_resource, |
| 3222 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3223 | "surface role already assigned"); |
| 3224 | return; |
| 3225 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3226 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3227 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3228 | weston_view_destroy(view); |
| 3229 | view = weston_view_create(surface); |
| 3230 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3231 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3232 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3233 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3234 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3235 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3236 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3237 | surface->output->width, |
| 3238 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3242 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3243 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3244 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3245 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3246 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3247 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3248 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3249 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3253 | desktop_shell_set_panel(struct wl_client *client, |
| 3254 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3255 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3256 | struct wl_resource *surface_resource) |
| 3257 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3258 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3259 | struct weston_surface *surface = |
| 3260 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3261 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3262 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3263 | if (surface->configure) { |
| 3264 | wl_resource_post_error(surface_resource, |
| 3265 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3266 | "surface role already assigned"); |
| 3267 | return; |
| 3268 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3269 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3270 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3271 | weston_view_destroy(view); |
| 3272 | view = weston_view_create(surface); |
| 3273 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3274 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3275 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3276 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3277 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3278 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3279 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3280 | surface->output->width, |
| 3281 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3282 | } |
| 3283 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3284 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3285 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3286 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3287 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3288 | struct weston_view *view; |
| 3289 | |
| 3290 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3291 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3292 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3293 | return; |
| 3294 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3295 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3296 | |
| 3297 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3298 | wl_list_insert(&shell->lock_layer.view_list, |
| 3299 | &view->layer_link); |
| 3300 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3301 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3306 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3307 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3308 | struct desktop_shell *shell = |
| 3309 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3310 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3311 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3312 | shell->lock_surface = NULL; |
| 3313 | } |
| 3314 | |
| 3315 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3316 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3317 | struct wl_resource *resource, |
| 3318 | struct wl_resource *surface_resource) |
| 3319 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3320 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3321 | struct weston_surface *surface = |
| 3322 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3323 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3324 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3325 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3326 | if (!shell->locked) |
| 3327 | return; |
| 3328 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3329 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3330 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3331 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3332 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3333 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3334 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3335 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3336 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3337 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3341 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3342 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3343 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3344 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3345 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3346 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3347 | wl_list_remove(&shell->lock_layer.link); |
| 3348 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3349 | &shell->fullscreen_layer.link); |
| 3350 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3351 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3352 | if (shell->showing_input_panels) { |
| 3353 | wl_list_insert(&shell->panel_layer.link, |
| 3354 | &shell->input_panel_layer.link); |
| 3355 | wl_list_insert(&shell->input_panel_layer.link, |
| 3356 | &ws->layer.link); |
| 3357 | } else { |
| 3358 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3359 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3360 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3361 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3362 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3363 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3364 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3365 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | static void |
| 3369 | desktop_shell_unlock(struct wl_client *client, |
| 3370 | struct wl_resource *resource) |
| 3371 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3372 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3373 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3374 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3375 | |
| 3376 | if (shell->locked) |
| 3377 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3378 | } |
| 3379 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3380 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3381 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3382 | struct wl_resource *resource, |
| 3383 | struct wl_resource *surface_resource) |
| 3384 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3385 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3386 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3387 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3388 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3389 | } |
| 3390 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3391 | static void |
| 3392 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3393 | struct wl_resource *resource) |
| 3394 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3395 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3396 | |
| 3397 | shell_fade_startup(shell); |
| 3398 | } |
| 3399 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3400 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3401 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3402 | desktop_shell_set_panel, |
| 3403 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3404 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3405 | desktop_shell_set_grab_surface, |
| 3406 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3407 | }; |
| 3408 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3409 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3410 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3411 | { |
| 3412 | struct shell_surface *shsurf; |
| 3413 | |
| 3414 | shsurf = get_shell_surface(surface); |
| 3415 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3416 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3417 | return shsurf->type; |
| 3418 | } |
| 3419 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3420 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3421 | 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] | 3422 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3423 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3424 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3425 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3426 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3427 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3428 | if (surface == NULL) |
| 3429 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3430 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3431 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3432 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3433 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3434 | return; |
| 3435 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3436 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3440 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3441 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3442 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3443 | struct weston_surface *surface; |
| 3444 | struct shell_surface *shsurf; |
| 3445 | |
| 3446 | surface = weston_surface_get_main_surface(focus); |
| 3447 | if (surface == NULL) |
| 3448 | return; |
| 3449 | |
| 3450 | shsurf = get_shell_surface(surface); |
| 3451 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3452 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
| 3453 | return; |
| 3454 | |
| 3455 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3456 | } |
| 3457 | |
| 3458 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3459 | 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] | 3460 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3461 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3462 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3463 | uint32_t edges = 0; |
| 3464 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3465 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3466 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3467 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3468 | if (surface == NULL) |
| 3469 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3470 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3471 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3472 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3473 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3474 | return; |
| 3475 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3476 | weston_view_from_global(shsurf->view, |
| 3477 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3478 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3479 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3480 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3481 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3482 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3483 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3484 | edges |= 0; |
| 3485 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3486 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3487 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3488 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3489 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3490 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3491 | edges |= 0; |
| 3492 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3493 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3494 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3495 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3499 | 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] | 3500 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3501 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3502 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3503 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3504 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3505 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3506 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3507 | /* XXX: broken for windows containing sub-surfaces */ |
| 3508 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3509 | if (surface == NULL) |
| 3510 | return; |
| 3511 | |
| 3512 | shsurf = get_shell_surface(surface); |
| 3513 | if (!shsurf) |
| 3514 | return; |
| 3515 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3516 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3517 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3518 | if (shsurf->view->alpha > 1.0) |
| 3519 | shsurf->view->alpha = 1.0; |
| 3520 | if (shsurf->view->alpha < step) |
| 3521 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3522 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3523 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3524 | weston_surface_damage(surface); |
| 3525 | } |
| 3526 | |
| 3527 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3528 | 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] | 3529 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3530 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3531 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3532 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3533 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3534 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3535 | |
| 3536 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3537 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3538 | wl_fixed_to_double(seat->pointer->x), |
| 3539 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3540 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3541 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3542 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3543 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3544 | increment = -output->zoom.increment; |
| 3545 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3546 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3547 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3548 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3549 | else |
| 3550 | increment = 0; |
| 3551 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3552 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3553 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3554 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3555 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3556 | else if (output->zoom.level > output->zoom.max_level) |
| 3557 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3558 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3559 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3560 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3561 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3562 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3563 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3564 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3565 | } |
| 3566 | } |
| 3567 | } |
| 3568 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3569 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3570 | 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] | 3571 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3572 | { |
| 3573 | do_zoom(seat, time, 0, axis, value); |
| 3574 | } |
| 3575 | |
| 3576 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3577 | 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] | 3578 | void *data) |
| 3579 | { |
| 3580 | do_zoom(seat, time, key, 0, 0); |
| 3581 | } |
| 3582 | |
| 3583 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3584 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3585 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3586 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3587 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3588 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3589 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3593 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 3594 | |
| 3595 | struct alt_tab { |
| 3596 | struct desktop_shell *shell; |
| 3597 | struct weston_keyboard_grab grab; |
| 3598 | |
| 3599 | struct wl_list *current; |
| 3600 | |
| 3601 | struct wl_list preview_list; |
| 3602 | }; |
| 3603 | |
| 3604 | struct alt_tab_preview { |
| 3605 | struct alt_tab *alt_tab; |
| 3606 | |
| 3607 | struct weston_view *view; |
| 3608 | struct weston_transform transform; |
| 3609 | |
| 3610 | struct wl_listener listener; |
| 3611 | |
| 3612 | struct wl_list link; |
| 3613 | }; |
| 3614 | |
| 3615 | static void |
| 3616 | alt_tab_next(struct alt_tab *alt_tab) |
| 3617 | { |
| 3618 | alt_tab->current = alt_tab->current->next; |
| 3619 | |
| 3620 | /* Make sure we're not pointing to the list header e.g. after |
| 3621 | * cycling through the whole list. */ |
| 3622 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3623 | alt_tab->current = alt_tab->current->next; |
| 3624 | } |
| 3625 | |
| 3626 | static void |
| 3627 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 3628 | { |
| 3629 | struct alt_tab_preview *preview, *next; |
| 3630 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 3631 | |
| 3632 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 3633 | preview = wl_container_of(alt_tab->current, preview, link); |
| 3634 | |
| 3635 | activate(alt_tab->shell, preview->view->surface, |
| 3636 | (struct weston_seat *) keyboard->seat); |
| 3637 | } |
| 3638 | |
| 3639 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 3640 | wl_list_remove(&preview->link); |
| 3641 | wl_list_remove(&preview->listener.link); |
| 3642 | weston_view_destroy(preview->view); |
| 3643 | free(preview); |
| 3644 | } |
| 3645 | |
| 3646 | weston_keyboard_end_grab(keyboard); |
| 3647 | if (keyboard->input_method_resource) |
| 3648 | keyboard->grab = &keyboard->input_method_grab; |
| 3649 | |
| 3650 | free(alt_tab); |
| 3651 | } |
| 3652 | |
| 3653 | static void |
| 3654 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3655 | { |
| 3656 | struct alt_tab_preview *preview = |
| 3657 | container_of(listener, struct alt_tab_preview, listener); |
| 3658 | struct alt_tab *alt_tab = preview->alt_tab; |
| 3659 | int advance = 0; |
| 3660 | |
| 3661 | /* If the preview that we're removing is the currently selected one, |
| 3662 | * we want to move to the next one. So we move to ->prev and then |
| 3663 | * call _next() after removing the preview. */ |
| 3664 | if (alt_tab->current == &preview->link) { |
| 3665 | alt_tab->current = alt_tab->current->prev; |
| 3666 | advance = 1; |
| 3667 | } |
| 3668 | |
| 3669 | wl_list_remove(&preview->listener.link); |
| 3670 | wl_list_remove(&preview->link); |
| 3671 | |
| 3672 | free(preview); |
| 3673 | |
| 3674 | if (advance) |
| 3675 | alt_tab_next(alt_tab); |
| 3676 | |
| 3677 | /* If the last preview goes away, stop the alt-tab */ |
| 3678 | if (wl_list_empty(alt_tab->current)) |
| 3679 | alt_tab_destroy(alt_tab); |
| 3680 | } |
| 3681 | |
| 3682 | static void |
| 3683 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 3684 | uint32_t time, uint32_t key, uint32_t state_w) |
| 3685 | { |
| 3686 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3687 | enum wl_keyboard_key_state state = state_w; |
| 3688 | |
| 3689 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 3690 | alt_tab_next(alt_tab); |
| 3691 | } |
| 3692 | |
| 3693 | static void |
| 3694 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 3695 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3696 | uint32_t mods_locked, uint32_t group) |
| 3697 | { |
| 3698 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3699 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 3700 | |
| 3701 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 3702 | alt_tab_destroy(alt_tab); |
| 3703 | } |
| 3704 | |
| 3705 | static void |
| 3706 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 3707 | { |
| 3708 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3709 | |
| 3710 | alt_tab_destroy(alt_tab); |
| 3711 | } |
| 3712 | |
| 3713 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 3714 | alt_tab_key, |
| 3715 | alt_tab_modifier, |
| 3716 | alt_tab_cancel, |
| 3717 | }; |
| 3718 | |
| 3719 | static int |
| 3720 | view_for_alt_tab(struct weston_view *view) |
| 3721 | { |
| 3722 | if (!get_shell_surface(view->surface)) |
| 3723 | return 0; |
| 3724 | |
| 3725 | if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT) |
| 3726 | return 0; |
| 3727 | |
| 3728 | if (view != get_default_view(view->surface)) |
| 3729 | return 0; |
| 3730 | |
| 3731 | return 1; |
| 3732 | } |
| 3733 | |
| 3734 | static void |
| 3735 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 3736 | void *data) |
| 3737 | { |
| 3738 | struct alt_tab *alt_tab; |
| 3739 | struct desktop_shell *shell = data; |
| 3740 | struct weston_output *output = get_default_output(shell->compositor); |
| 3741 | struct workspace *ws; |
| 3742 | struct weston_view *view; |
| 3743 | int num_surfaces = 0; |
| 3744 | int x, y, side, margin; |
| 3745 | |
| 3746 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3747 | |
| 3748 | if (view_for_alt_tab(view)) |
| 3749 | num_surfaces++; |
| 3750 | } |
| 3751 | |
| 3752 | if (!num_surfaces) |
| 3753 | return; |
| 3754 | |
| 3755 | alt_tab = malloc(sizeof *alt_tab); |
| 3756 | if (!alt_tab) |
| 3757 | return; |
| 3758 | |
| 3759 | alt_tab->shell = shell; |
| 3760 | wl_list_init(&alt_tab->preview_list); |
| 3761 | alt_tab->current = &alt_tab->preview_list; |
| 3762 | |
| 3763 | restore_all_output_modes(shell->compositor); |
| 3764 | lower_fullscreen_layer(alt_tab->shell); |
| 3765 | |
| 3766 | alt_tab->grab.interface = &alt_tab_grab; |
| 3767 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 3768 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 3769 | |
| 3770 | ws = get_current_workspace(shell); |
| 3771 | |
| 3772 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 3773 | * and/or add a black surrounding background à la gnome-shell */ |
| 3774 | |
| 3775 | /* Determine the size for each preview */ |
| 3776 | side = output->width / num_surfaces; |
| 3777 | if (side > 200) |
| 3778 | side = 200; |
| 3779 | margin = side / 4; |
| 3780 | side -= margin; |
| 3781 | |
| 3782 | x = margin; |
| 3783 | y = (output->height - side) / 2; |
| 3784 | |
| 3785 | /* Create a view for each surface */ |
| 3786 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3787 | struct alt_tab_preview *preview; |
| 3788 | struct weston_view *v; |
| 3789 | float scale; |
| 3790 | |
| 3791 | if (!view_for_alt_tab(view)) |
| 3792 | continue; |
| 3793 | |
| 3794 | preview = malloc(sizeof *preview); |
| 3795 | if (!preview) { |
| 3796 | alt_tab_destroy(alt_tab); |
| 3797 | return; |
| 3798 | } |
| 3799 | |
| 3800 | preview->alt_tab = alt_tab; |
| 3801 | |
| 3802 | preview->view = v = weston_view_create(view->surface); |
| 3803 | v->output = view->output; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 3804 | |
| 3805 | wl_list_remove(&v->layer_link); |
| 3806 | wl_list_insert(&ws->layer.view_list, &v->layer_link); |
| 3807 | weston_view_damage_below(v); |
| 3808 | weston_surface_damage(v->surface); |
| 3809 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3810 | weston_view_set_position(v, x, y); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3811 | |
| 3812 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 3813 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 3814 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3815 | if (view->surface->width > view->surface->height) |
| 3816 | scale = side / (float) view->surface->width; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3817 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3818 | scale = side / (float) view->surface->height; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3819 | |
| 3820 | wl_list_insert(&v->geometry.transformation_list, |
| 3821 | &preview->transform.link); |
| 3822 | weston_matrix_init(&preview->transform.matrix); |
| 3823 | weston_matrix_scale(&preview->transform.matrix, |
| 3824 | scale, scale, 1.0f); |
| 3825 | |
| 3826 | weston_view_geometry_dirty(v); |
| 3827 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 3828 | |
| 3829 | /* Insert at the end of the list */ |
| 3830 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 3831 | |
| 3832 | x += side + margin; |
| 3833 | } |
| 3834 | |
| 3835 | /* Start at the second preview so a simple <alt>tab changes window. |
| 3836 | * We set `current' to the first preview and not the second because |
| 3837 | * we're going to receive a key press callback for the initial |
| 3838 | * <alt>tab which will make `current' point to the second element. */ |
| 3839 | alt_tab_next(alt_tab); |
| 3840 | } |
| 3841 | |
| 3842 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3843 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3844 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3845 | { |
| 3846 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3847 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3848 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3849 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3850 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3851 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3852 | weston_pointer_move(pointer, x, y); |
| 3853 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3854 | if (!shsurf) |
| 3855 | return; |
| 3856 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3857 | cx = 0.5f * shsurf->surface->width; |
| 3858 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3859 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3860 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3861 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3862 | r = sqrtf(dx * dx + dy * dy); |
| 3863 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3864 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3865 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3866 | |
| 3867 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3868 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3869 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3870 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3871 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3872 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3873 | |
| 3874 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3875 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3876 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3877 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3878 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3879 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3880 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3881 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3882 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3883 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3884 | wl_list_init(&shsurf->rotation.transform.link); |
| 3885 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3886 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3887 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3888 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3889 | /* We need to adjust the position of the surface |
| 3890 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3891 | cposx = shsurf->view->geometry.x + cx; |
| 3892 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3893 | dposx = rotate->center.x - cposx; |
| 3894 | dposy = rotate->center.y - cposy; |
| 3895 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3896 | weston_view_set_position(shsurf->view, |
| 3897 | shsurf->view->geometry.x + dposx, |
| 3898 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3899 | } |
| 3900 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3901 | /* Repaint implies weston_surface_update_transform(), which |
| 3902 | * lazily applies the damage due to rotation update. |
| 3903 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3904 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3908 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3909 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3910 | { |
| 3911 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3912 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3913 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3914 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3915 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3916 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3917 | if (pointer->button_count == 0 && |
| 3918 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3919 | if (shsurf) |
| 3920 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3921 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3922 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3923 | free(rotate); |
| 3924 | } |
| 3925 | } |
| 3926 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3927 | static void |
| 3928 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3929 | { |
| 3930 | struct rotate_grab *rotate = |
| 3931 | container_of(grab, struct rotate_grab, base.grab); |
| 3932 | |
| 3933 | shell_grab_end(&rotate->base); |
| 3934 | free(rotate); |
| 3935 | } |
| 3936 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3937 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3938 | noop_grab_focus, |
| 3939 | rotate_grab_motion, |
| 3940 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3941 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3942 | }; |
| 3943 | |
| 3944 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3945 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3946 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3947 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3948 | float dx, dy; |
| 3949 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3950 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3951 | rotate = malloc(sizeof *rotate); |
| 3952 | if (!rotate) |
| 3953 | return; |
| 3954 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3955 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 3956 | surface->surface->width * 0.5f, |
| 3957 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3958 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3959 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3960 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3961 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3962 | r = sqrtf(dx * dx + dy * dy); |
| 3963 | if (r > 20.0f) { |
| 3964 | struct weston_matrix inverse; |
| 3965 | |
| 3966 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3967 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3968 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3969 | |
| 3970 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3971 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3972 | } else { |
| 3973 | weston_matrix_init(&surface->rotation.rotation); |
| 3974 | weston_matrix_init(&rotate->rotation); |
| 3975 | } |
| 3976 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3977 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3978 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3982 | 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] | 3983 | void *data) |
| 3984 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3985 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3986 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3987 | struct shell_surface *surface; |
| 3988 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3989 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3990 | if (base_surface == NULL) |
| 3991 | return; |
| 3992 | |
| 3993 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3994 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 3995 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3996 | return; |
| 3997 | |
| 3998 | surface_rotate(surface, seat); |
| 3999 | } |
| 4000 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4001 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4002 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4003 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4004 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4005 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4006 | { |
| 4007 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4008 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4009 | |
| 4010 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4011 | wl_list_for_each_reverse_safe(view, prev, |
| 4012 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4013 | layer_link) { |
| 4014 | wl_list_remove(&view->layer_link); |
| 4015 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4016 | weston_view_damage_below(view); |
| 4017 | weston_surface_damage(view->surface); |
| 4018 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4022 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4023 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4024 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4025 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4026 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4027 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4028 | struct weston_surface *old_es; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4029 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4030 | main_surface = weston_surface_get_main_surface(es); |
| 4031 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4032 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4033 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4034 | state = ensure_focus_state(shell, seat); |
| 4035 | if (state == NULL) |
| 4036 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4037 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4038 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4039 | state->keyboard_focus = es; |
| 4040 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4041 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4042 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4043 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4044 | case SHELL_SURFACE_FULLSCREEN: |
| 4045 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4046 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4047 | return; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4048 | case SHELL_SURFACE_TOPLEVEL: |
| 4049 | case SHELL_SURFACE_TRANSIENT: |
| 4050 | case SHELL_SURFACE_MAXIMIZED: |
| 4051 | case SHELL_SURFACE_POPUP: |
| 4052 | case SHELL_SURFACE_XWAYLAND: |
| 4053 | case SHELL_SURFACE_NONE: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4054 | default: |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4055 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4056 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4057 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4058 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4059 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4060 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4061 | animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es)); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4065 | * order as appropriate. */ |
| 4066 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4067 | } |
| 4068 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4069 | /* no-op func for checking black surface */ |
| 4070 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4071 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4072 | { |
| 4073 | } |
| 4074 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4075 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4076 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4077 | { |
| 4078 | if (es->configure == black_surface_configure) { |
| 4079 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4080 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4081 | return true; |
| 4082 | } |
| 4083 | return false; |
| 4084 | } |
| 4085 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4086 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4087 | activate_binding(struct weston_seat *seat, |
| 4088 | struct desktop_shell *shell, |
| 4089 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4090 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4091 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4092 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4093 | if (!focus) |
| 4094 | return; |
| 4095 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4096 | if (is_black_surface(focus, &main_surface)) |
| 4097 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4098 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4099 | main_surface = weston_surface_get_main_surface(focus); |
| 4100 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4101 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4102 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4103 | activate(shell, focus, seat); |
| 4104 | } |
| 4105 | |
| 4106 | static void |
| 4107 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4108 | void *data) |
| 4109 | { |
| 4110 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4111 | return; |
| 4112 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4113 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | static void |
| 4117 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4118 | { |
| 4119 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4120 | return; |
| 4121 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4122 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4126 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4127 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4128 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4129 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4130 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4131 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4132 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4133 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4134 | |
| 4135 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4136 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4137 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4138 | * toplevel layers. This way nothing else can show or receive |
| 4139 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4140 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4141 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4142 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4143 | if (shell->showing_input_panels) |
| 4144 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4145 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4146 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4147 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4148 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4149 | launch_screensaver(shell); |
| 4150 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4151 | /* TODO: disable bindings that should not work while locked. */ |
| 4152 | |
| 4153 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4154 | } |
| 4155 | |
| 4156 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4157 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4158 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4159 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4160 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4161 | return; |
| 4162 | } |
| 4163 | |
| 4164 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4165 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4166 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4167 | return; |
| 4168 | } |
| 4169 | |
| 4170 | if (shell->prepare_event_sent) |
| 4171 | return; |
| 4172 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4173 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4174 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4178 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4179 | { |
| 4180 | struct desktop_shell *shell = data; |
| 4181 | |
| 4182 | shell->fade.animation = NULL; |
| 4183 | |
| 4184 | switch (shell->fade.type) { |
| 4185 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4186 | weston_surface_destroy(shell->fade.view->surface); |
| 4187 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4188 | break; |
| 4189 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4190 | lock(shell); |
| 4191 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4192 | default: |
| 4193 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4194 | } |
| 4195 | } |
| 4196 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4197 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4198 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4199 | { |
| 4200 | struct weston_compositor *compositor = shell->compositor; |
| 4201 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4202 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4203 | |
| 4204 | surface = weston_surface_create(compositor); |
| 4205 | if (!surface) |
| 4206 | return NULL; |
| 4207 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4208 | view = weston_view_create(surface); |
| 4209 | if (!view) { |
| 4210 | weston_surface_destroy(surface); |
| 4211 | return NULL; |
| 4212 | } |
| 4213 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4214 | surface->width = 8192; |
| 4215 | surface->height = 8192; |
| 4216 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4217 | 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] | 4218 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4219 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4220 | pixman_region32_init(&surface->input); |
| 4221 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4222 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | static void |
| 4226 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4227 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4228 | float tint; |
| 4229 | |
| 4230 | switch (type) { |
| 4231 | case FADE_IN: |
| 4232 | tint = 0.0; |
| 4233 | break; |
| 4234 | case FADE_OUT: |
| 4235 | tint = 1.0; |
| 4236 | break; |
| 4237 | default: |
| 4238 | weston_log("shell: invalid fade type\n"); |
| 4239 | return; |
| 4240 | } |
| 4241 | |
| 4242 | shell->fade.type = type; |
| 4243 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4244 | if (shell->fade.view == NULL) { |
| 4245 | shell->fade.view = shell_fade_create_surface(shell); |
| 4246 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4247 | return; |
| 4248 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4249 | shell->fade.view->alpha = 1.0 - tint; |
| 4250 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4254 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4255 | else |
| 4256 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4257 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4258 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4259 | shell_fade_done, shell); |
| 4260 | } |
| 4261 | |
| 4262 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4263 | do_shell_fade_startup(void *data) |
| 4264 | { |
| 4265 | struct desktop_shell *shell = data; |
| 4266 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4267 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4268 | shell_fade(shell, FADE_IN); |
| 4269 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4270 | weston_surface_destroy(shell->fade.view->surface); |
| 4271 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4272 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | static void |
| 4276 | shell_fade_startup(struct desktop_shell *shell) |
| 4277 | { |
| 4278 | struct wl_event_loop *loop; |
| 4279 | |
| 4280 | if (!shell->fade.startup_timer) |
| 4281 | return; |
| 4282 | |
| 4283 | wl_event_source_remove(shell->fade.startup_timer); |
| 4284 | shell->fade.startup_timer = NULL; |
| 4285 | |
| 4286 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4287 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4288 | } |
| 4289 | |
| 4290 | static int |
| 4291 | fade_startup_timeout(void *data) |
| 4292 | { |
| 4293 | struct desktop_shell *shell = data; |
| 4294 | |
| 4295 | shell_fade_startup(shell); |
| 4296 | return 0; |
| 4297 | } |
| 4298 | |
| 4299 | static void |
| 4300 | shell_fade_init(struct desktop_shell *shell) |
| 4301 | { |
| 4302 | /* Make compositor output all black, and wait for the desktop-shell |
| 4303 | * client to signal it is ready, then fade in. The timer triggers a |
| 4304 | * fade-in, in case the desktop-shell client takes too long. |
| 4305 | */ |
| 4306 | |
| 4307 | struct wl_event_loop *loop; |
| 4308 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4309 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4310 | weston_log("%s: warning: fade surface already exists\n", |
| 4311 | __func__); |
| 4312 | return; |
| 4313 | } |
| 4314 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4315 | shell->fade.view = shell_fade_create_surface(shell); |
| 4316 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4317 | return; |
| 4318 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4319 | weston_view_update_transform(shell->fade.view); |
| 4320 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4321 | |
| 4322 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4323 | shell->fade.startup_timer = |
| 4324 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4325 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4326 | } |
| 4327 | |
| 4328 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4329 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4330 | { |
| 4331 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4332 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4333 | |
| 4334 | shell_fade(shell, FADE_OUT); |
| 4335 | /* lock() is called from shell_fade_done() */ |
| 4336 | } |
| 4337 | |
| 4338 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4339 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4340 | { |
| 4341 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4342 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4343 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4344 | unlock(shell); |
| 4345 | } |
| 4346 | |
| 4347 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4348 | show_input_panels(struct wl_listener *listener, void *data) |
| 4349 | { |
| 4350 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4351 | container_of(listener, struct desktop_shell, |
| 4352 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4353 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4354 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4355 | shell->text_input.surface = (struct weston_surface*)data; |
| 4356 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4357 | if (shell->showing_input_panels) |
| 4358 | return; |
| 4359 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4360 | shell->showing_input_panels = true; |
| 4361 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4362 | if (!shell->locked) |
| 4363 | wl_list_insert(&shell->panel_layer.link, |
| 4364 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4365 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4366 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4367 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4368 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4369 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4370 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4371 | &ipsurf->view->layer_link); |
| 4372 | weston_view_geometry_dirty(ipsurf->view); |
| 4373 | weston_view_update_transform(ipsurf->view); |
| 4374 | weston_surface_damage(ipsurf->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4375 | weston_slide_run(ipsurf->view, ipsurf->surface->height, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4376 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | static void |
| 4381 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4382 | { |
| 4383 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4384 | container_of(listener, struct desktop_shell, |
| 4385 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4386 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4387 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4388 | if (!shell->showing_input_panels) |
| 4389 | return; |
| 4390 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4391 | shell->showing_input_panels = false; |
| 4392 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4393 | if (!shell->locked) |
| 4394 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4395 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4396 | wl_list_for_each_safe(view, next, |
| 4397 | &shell->input_panel_layer.view_list, layer_link) |
| 4398 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4402 | update_input_panels(struct wl_listener *listener, void *data) |
| 4403 | { |
| 4404 | struct desktop_shell *shell = |
| 4405 | container_of(listener, struct desktop_shell, |
| 4406 | update_input_panel_listener); |
| 4407 | |
| 4408 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4409 | } |
| 4410 | |
| 4411 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4412 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4413 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4414 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4415 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4416 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4417 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4418 | |
| 4419 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4420 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4421 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4422 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4426 | weston_view_set_initial_position(struct weston_view *view, |
| 4427 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4428 | { |
| 4429 | struct weston_compositor *compositor = shell->compositor; |
| 4430 | int ix = 0, iy = 0; |
| 4431 | int range_x, range_y; |
| 4432 | int dx, dy, x, y, panel_height; |
| 4433 | struct weston_output *output, *target_output = NULL; |
| 4434 | struct weston_seat *seat; |
| 4435 | |
| 4436 | /* As a heuristic place the new window on the same output as the |
| 4437 | * pointer. Falling back to the output containing 0, 0. |
| 4438 | * |
| 4439 | * TODO: Do something clever for touch too? |
| 4440 | */ |
| 4441 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4442 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4443 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4444 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4445 | break; |
| 4446 | } |
| 4447 | } |
| 4448 | |
| 4449 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4450 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4451 | target_output = output; |
| 4452 | break; |
| 4453 | } |
| 4454 | } |
| 4455 | |
| 4456 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4457 | weston_view_set_position(view, 10 + random() % 400, |
| 4458 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4459 | return; |
| 4460 | } |
| 4461 | |
| 4462 | /* Valid range within output where the surface will still be onscreen. |
| 4463 | * If this is negative it means that the surface is bigger than |
| 4464 | * output. |
| 4465 | */ |
| 4466 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4467 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4468 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4469 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4470 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4471 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4472 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4473 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4474 | dx = 0; |
| 4475 | |
| 4476 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4477 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4478 | else |
| 4479 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4480 | |
| 4481 | x = target_output->x + dx; |
| 4482 | y = target_output->y + dy; |
| 4483 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4484 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4488 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4489 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4490 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4491 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4492 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4493 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4494 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4495 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4496 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4497 | switch (shsurf->type) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4498 | case SHELL_SURFACE_TOPLEVEL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4499 | weston_view_set_initial_position(shsurf->view, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4500 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4501 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4502 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4503 | shell_map_fullscreen(shsurf); |
| 4504 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4505 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4506 | /* use surface configure to set the geometry */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4507 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4508 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4509 | &surf_x, &surf_y, NULL, NULL); |
| 4510 | weston_view_set_position(shsurf->view, |
| 4511 | shsurf->output->x - surf_x, |
| 4512 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4513 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4514 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4515 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4516 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4517 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4518 | weston_view_set_position(shsurf->view, |
| 4519 | shsurf->view->geometry.x + sx, |
| 4520 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4521 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4522 | case SHELL_SURFACE_TRANSIENT: |
| 4523 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4524 | default: |
| 4525 | ; |
| 4526 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4527 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 4528 | /* Surface stacking order, see also activate(). */ |
| 4529 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4530 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4531 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4532 | weston_view_update_transform(shsurf->view); |
| 4533 | if (shsurf->type == SHELL_SURFACE_MAXIMIZED) { |
| 4534 | shsurf->surface->output = shsurf->output; |
| 4535 | shsurf->view->output = shsurf->output; |
| 4536 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4537 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4538 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4539 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4540 | /* XXX: xwayland's using the same fields for transient type */ |
| 4541 | case SHELL_SURFACE_XWAYLAND: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4542 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4543 | if (shsurf->transient.flags == |
| 4544 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4545 | break; |
| 4546 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4547 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4548 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4549 | if (!shell->locked) { |
| 4550 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4551 | activate(shell, shsurf->surface, seat); |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4552 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4553 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4554 | case SHELL_SURFACE_POPUP: |
| 4555 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4556 | default: |
| 4557 | break; |
| 4558 | } |
| 4559 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4560 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4561 | { |
| 4562 | switch (shell->win_animation_type) { |
| 4563 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4564 | 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] | 4565 | break; |
| 4566 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4567 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4568 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4569 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4570 | default: |
| 4571 | break; |
| 4572 | } |
| 4573 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4577 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4578 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4579 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4580 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 4581 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4582 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4583 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4584 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4585 | shsurf = get_shell_surface(surface); |
| 4586 | if (shsurf) |
| 4587 | surface_type = shsurf->type; |
| 4588 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4589 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4590 | case SHELL_SURFACE_FULLSCREEN: |
| 4591 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4592 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4593 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4594 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4595 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4596 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4597 | mx = shsurf->output->x - surf_x; |
| 4598 | my = shsurf->output->y + |
| 4599 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 4600 | weston_view_set_position(shsurf->view, mx, my); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4601 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4602 | case SHELL_SURFACE_TOPLEVEL: |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 4603 | case SHELL_SURFACE_TRANSIENT: |
| 4604 | case SHELL_SURFACE_POPUP: |
| 4605 | case SHELL_SURFACE_XWAYLAND: |
| 4606 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4607 | default: |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4608 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4609 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4610 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4611 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4612 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4613 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4614 | wl_list_for_each(view, &surface->views, surface_link) |
| 4615 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4616 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4617 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4618 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4619 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4620 | } |
| 4621 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4622 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4623 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4624 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4625 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4626 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4627 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4628 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4629 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4630 | if (!weston_surface_is_mapped(es) && |
| 4631 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4632 | remove_popup_grab(shsurf); |
| 4633 | } |
| 4634 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4635 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4636 | return; |
| 4637 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4638 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4639 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4640 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4641 | type_changed = 1; |
| 4642 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4643 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4644 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4645 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4646 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4647 | shsurf->last_width != es->width || |
| 4648 | shsurf->last_height != es->height) { |
| 4649 | shsurf->last_width = es->width; |
| 4650 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4651 | float from_x, from_y; |
| 4652 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4653 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4654 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4655 | 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] | 4656 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4657 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4658 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4659 | } |
| 4660 | } |
| 4661 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4662 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4663 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4664 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4665 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4666 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4667 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4668 | struct desktop_shell *shell = |
| 4669 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4670 | |
| 4671 | shell->child.process.pid = 0; |
| 4672 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4673 | |
| 4674 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4675 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4676 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4677 | shell->child.deathstamp = time; |
| 4678 | shell->child.deathcount = 0; |
| 4679 | } |
| 4680 | |
| 4681 | shell->child.deathcount++; |
| 4682 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4683 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4684 | return; |
| 4685 | } |
| 4686 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4687 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4688 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4689 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4690 | } |
| 4691 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4692 | static void |
| 4693 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4694 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4695 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4696 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4697 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4698 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4699 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4700 | desktop_shell_sigchld); |
| 4701 | |
| 4702 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 4703 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4704 | } |
| 4705 | |
| 4706 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4707 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4708 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4709 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4710 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4711 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4712 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4713 | if (resource) |
| 4714 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4715 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4716 | } |
| 4717 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4718 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4719 | unbind_desktop_shell(struct wl_resource *resource) |
| 4720 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4721 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4722 | |
| 4723 | if (shell->locked) |
| 4724 | resume_desktop(shell); |
| 4725 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4726 | shell->child.desktop_shell = NULL; |
| 4727 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4731 | bind_desktop_shell(struct wl_client *client, |
| 4732 | void *data, uint32_t version, uint32_t id) |
| 4733 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4734 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4735 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4736 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4737 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4738 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4739 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4740 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4741 | wl_resource_set_implementation(resource, |
| 4742 | &desktop_shell_implementation, |
| 4743 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4744 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4745 | |
| 4746 | if (version < 2) |
| 4747 | shell_fade_startup(shell); |
| 4748 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4749 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4750 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4751 | |
| 4752 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4753 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4754 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4755 | } |
| 4756 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4757 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4758 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4759 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4760 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4761 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4762 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4763 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4764 | return; |
| 4765 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4766 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4767 | if (!shell->locked) |
| 4768 | return; |
| 4769 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4770 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4771 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4772 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4773 | if (wl_list_empty(&view->layer_link)) { |
| 4774 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4775 | &view->layer_link); |
| 4776 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4777 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4778 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4779 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4784 | screensaver_set_surface(struct wl_client *client, |
| 4785 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4786 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4787 | struct wl_resource *output_resource) |
| 4788 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4789 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4790 | struct weston_surface *surface = |
| 4791 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4792 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4793 | struct weston_view *view, *next; |
| 4794 | |
| 4795 | /* Make sure we only have one view */ |
| 4796 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4797 | weston_view_destroy(view); |
| 4798 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4799 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4800 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4801 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4802 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | static const struct screensaver_interface screensaver_implementation = { |
| 4806 | screensaver_set_surface |
| 4807 | }; |
| 4808 | |
| 4809 | static void |
| 4810 | unbind_screensaver(struct wl_resource *resource) |
| 4811 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4812 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4813 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4814 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | static void |
| 4818 | bind_screensaver(struct wl_client *client, |
| 4819 | void *data, uint32_t version, uint32_t id) |
| 4820 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4821 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4822 | struct wl_resource *resource; |
| 4823 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4824 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4825 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4826 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4827 | wl_resource_set_implementation(resource, |
| 4828 | &screensaver_implementation, |
| 4829 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4830 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4831 | return; |
| 4832 | } |
| 4833 | |
| 4834 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4835 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4836 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4837 | } |
| 4838 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4839 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4840 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4841 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4842 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4843 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4844 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4845 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4846 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4847 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4848 | return; |
| 4849 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4850 | if (!weston_surface_is_mapped(surface)) { |
| 4851 | if (!shell->showing_input_panels) |
| 4852 | return; |
| 4853 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4854 | show_surface = 1; |
| 4855 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4856 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4857 | 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] | 4858 | |
| 4859 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4860 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4861 | 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] | 4862 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4863 | x = ip_surface->output->x + (ip_surface->output->width - surface->width) / 2; |
| 4864 | y = ip_surface->output->y + ip_surface->output->height - surface->height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4865 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4866 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4867 | weston_view_set_position(ip_surface->view, x, y); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4868 | |
| 4869 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4870 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4871 | &ip_surface->view->layer_link); |
| 4872 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4873 | weston_surface_damage(surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 4874 | weston_slide_run(ip_surface->view, ip_surface->view->surface->height, 0, NULL, NULL); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4875 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4876 | } |
| 4877 | |
| 4878 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4879 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4880 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4881 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4882 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4883 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4884 | wl_list_remove(&input_panel_surface->link); |
| 4885 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4886 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4887 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4888 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4889 | free(input_panel_surface); |
| 4890 | } |
| 4891 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4892 | static struct input_panel_surface * |
| 4893 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4894 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4895 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4896 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4897 | } else { |
| 4898 | return NULL; |
| 4899 | } |
| 4900 | } |
| 4901 | |
| 4902 | static void |
| 4903 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4904 | { |
| 4905 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4906 | struct input_panel_surface, |
| 4907 | surface_destroy_listener); |
| 4908 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4909 | if (ipsurface->resource) { |
| 4910 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4911 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4912 | destroy_input_panel_surface(ipsurface); |
| 4913 | } |
| 4914 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4915 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4916 | static struct input_panel_surface * |
| 4917 | create_input_panel_surface(struct desktop_shell *shell, |
| 4918 | struct weston_surface *surface) |
| 4919 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4920 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4921 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4922 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4923 | if (!input_panel_surface) |
| 4924 | return NULL; |
| 4925 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4926 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4927 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4928 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4929 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4930 | |
| 4931 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4932 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4933 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4934 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4935 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4936 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4937 | &input_panel_surface->surface_destroy_listener); |
| 4938 | |
| 4939 | wl_list_init(&input_panel_surface->link); |
| 4940 | |
| 4941 | return input_panel_surface; |
| 4942 | } |
| 4943 | |
| 4944 | static void |
| 4945 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4946 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4947 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4948 | uint32_t position) |
| 4949 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4950 | struct input_panel_surface *input_panel_surface = |
| 4951 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4952 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4953 | |
| 4954 | wl_list_insert(&shell->input_panel.surfaces, |
| 4955 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4956 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4957 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4958 | input_panel_surface->panel = 0; |
| 4959 | } |
| 4960 | |
| 4961 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4962 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4963 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4964 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4965 | struct input_panel_surface *input_panel_surface = |
| 4966 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4967 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4968 | |
| 4969 | wl_list_insert(&shell->input_panel.surfaces, |
| 4970 | &input_panel_surface->link); |
| 4971 | |
| 4972 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4973 | } |
| 4974 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4975 | 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] | 4976 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4977 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4978 | }; |
| 4979 | |
| 4980 | static void |
| 4981 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4982 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4983 | struct input_panel_surface *ipsurf = |
| 4984 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4985 | |
| 4986 | destroy_input_panel_surface(ipsurf); |
| 4987 | } |
| 4988 | |
| 4989 | static void |
| 4990 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4991 | struct wl_resource *resource, |
| 4992 | uint32_t id, |
| 4993 | struct wl_resource *surface_resource) |
| 4994 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4995 | struct weston_surface *surface = |
| 4996 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4997 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4998 | struct input_panel_surface *ipsurf; |
| 4999 | |
| 5000 | if (get_input_panel_surface(surface)) { |
| 5001 | wl_resource_post_error(surface_resource, |
| 5002 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5003 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5004 | return; |
| 5005 | } |
| 5006 | |
| 5007 | ipsurf = create_input_panel_surface(shell, surface); |
| 5008 | if (!ipsurf) { |
| 5009 | wl_resource_post_error(surface_resource, |
| 5010 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5011 | "surface->configure already set"); |
| 5012 | return; |
| 5013 | } |
| 5014 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5015 | ipsurf->resource = |
| 5016 | wl_resource_create(client, |
| 5017 | &wl_input_panel_surface_interface, 1, id); |
| 5018 | wl_resource_set_implementation(ipsurf->resource, |
| 5019 | &input_panel_surface_implementation, |
| 5020 | ipsurf, |
| 5021 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5022 | } |
| 5023 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5024 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5025 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5026 | }; |
| 5027 | |
| 5028 | static void |
| 5029 | unbind_input_panel(struct wl_resource *resource) |
| 5030 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5031 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5032 | |
| 5033 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5034 | } |
| 5035 | |
| 5036 | static void |
| 5037 | bind_input_panel(struct wl_client *client, |
| 5038 | void *data, uint32_t version, uint32_t id) |
| 5039 | { |
| 5040 | struct desktop_shell *shell = data; |
| 5041 | struct wl_resource *resource; |
| 5042 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5043 | resource = wl_resource_create(client, |
| 5044 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5045 | |
| 5046 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5047 | wl_resource_set_implementation(resource, |
| 5048 | &input_panel_implementation, |
| 5049 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5050 | shell->input_panel.binding = resource; |
| 5051 | return; |
| 5052 | } |
| 5053 | |
| 5054 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5055 | "interface object already bound"); |
| 5056 | wl_resource_destroy(resource); |
| 5057 | } |
| 5058 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5059 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5060 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5061 | struct weston_surface *current; |
| 5062 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5063 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5064 | }; |
| 5065 | |
| 5066 | static void |
| 5067 | switcher_next(struct switcher *switcher) |
| 5068 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5069 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5070 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5071 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5072 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5073 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5074 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 5075 | switch (get_shell_surface_type(view->surface)) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5076 | case SHELL_SURFACE_TOPLEVEL: |
| 5077 | case SHELL_SURFACE_FULLSCREEN: |
| 5078 | case SHELL_SURFACE_MAXIMIZED: |
| 5079 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5080 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5081 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5082 | next = view->surface; |
| 5083 | prev = view->surface; |
| 5084 | view->alpha = 0.25; |
| 5085 | weston_view_geometry_dirty(view); |
| 5086 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5087 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5088 | case SHELL_SURFACE_TRANSIENT: |
| 5089 | case SHELL_SURFACE_POPUP: |
| 5090 | case SHELL_SURFACE_XWAYLAND: |
| 5091 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5092 | default: |
| 5093 | break; |
| 5094 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5095 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5096 | if (is_black_surface(view->surface, NULL)) { |
| 5097 | view->alpha = 0.25; |
| 5098 | weston_view_geometry_dirty(view); |
| 5099 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5100 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | if (next == NULL) |
| 5104 | next = first; |
| 5105 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5106 | if (next == NULL) |
| 5107 | return; |
| 5108 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5109 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5110 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5111 | |
| 5112 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5113 | wl_list_for_each(view, &next->views, surface_link) |
| 5114 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5115 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5116 | shsurf = get_shell_surface(switcher->current); |
| 5117 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5118 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5122 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5123 | { |
| 5124 | struct switcher *switcher = |
| 5125 | container_of(listener, struct switcher, listener); |
| 5126 | |
| 5127 | switcher_next(switcher); |
| 5128 | } |
| 5129 | |
| 5130 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5131 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5132 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5133 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5134 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5135 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5136 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5137 | 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] | 5138 | if (is_focus_view(view)) |
| 5139 | continue; |
| 5140 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5141 | view->alpha = 1.0; |
| 5142 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5143 | } |
| 5144 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5145 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5146 | activate(switcher->shell, switcher->current, |
| 5147 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5148 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5149 | weston_keyboard_end_grab(keyboard); |
| 5150 | if (keyboard->input_method_resource) |
| 5151 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5152 | free(switcher); |
| 5153 | } |
| 5154 | |
| 5155 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5156 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5157 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5158 | { |
| 5159 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5160 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5161 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5162 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5163 | switcher_next(switcher); |
| 5164 | } |
| 5165 | |
| 5166 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5167 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5168 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5169 | uint32_t mods_locked, uint32_t group) |
| 5170 | { |
| 5171 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5172 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5173 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5174 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5175 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5176 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5177 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5178 | static void |
| 5179 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5180 | { |
| 5181 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5182 | |
| 5183 | switcher_destroy(switcher); |
| 5184 | } |
| 5185 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5186 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5187 | switcher_key, |
| 5188 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5189 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5190 | }; |
| 5191 | |
| 5192 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5193 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5194 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5195 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5196 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5197 | struct switcher *switcher; |
| 5198 | |
| 5199 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5200 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5201 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5202 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5203 | wl_list_init(&switcher->listener.link); |
| 5204 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5205 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5206 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5207 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5208 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5209 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5210 | switcher_next(switcher); |
| 5211 | } |
| 5212 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5213 | struct exposay_surface { |
| 5214 | struct desktop_shell *shell; |
| 5215 | struct weston_surface *surface; |
| 5216 | struct weston_view *view; |
| 5217 | struct wl_list link; |
| 5218 | |
| 5219 | int x; |
| 5220 | int y; |
| 5221 | int width; |
| 5222 | int height; |
| 5223 | double scale; |
| 5224 | |
| 5225 | int row; |
| 5226 | int column; |
| 5227 | |
| 5228 | /* The animations only apply a transformation for their own lifetime, |
| 5229 | * and don't have an option to indefinitely maintain the |
| 5230 | * transformation in a steady state - so, we apply our own once the |
| 5231 | * animation has finished. */ |
| 5232 | struct weston_transform transform; |
| 5233 | }; |
| 5234 | |
| 5235 | static void exposay_set_state(struct desktop_shell *shell, |
| 5236 | enum exposay_target_state state, |
| 5237 | struct weston_seat *seat); |
| 5238 | static void exposay_check_state(struct desktop_shell *shell); |
| 5239 | |
| 5240 | static void |
| 5241 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 5242 | { |
| 5243 | shell->exposay.in_flight++; |
| 5244 | } |
| 5245 | |
| 5246 | static void |
| 5247 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5248 | { |
| 5249 | if (--shell->exposay.in_flight > 0) |
| 5250 | return; |
| 5251 | |
| 5252 | exposay_check_state(shell); |
| 5253 | } |
| 5254 | |
| 5255 | static void |
| 5256 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5257 | { |
| 5258 | struct exposay_surface *esurface = data; |
| 5259 | |
| 5260 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5261 | &esurface->transform.link); |
| 5262 | weston_matrix_init(&esurface->transform.matrix); |
| 5263 | weston_matrix_scale(&esurface->transform.matrix, |
| 5264 | esurface->scale, esurface->scale, 1.0f); |
| 5265 | weston_matrix_translate(&esurface->transform.matrix, |
| 5266 | esurface->x - esurface->view->geometry.x, |
| 5267 | esurface->y - esurface->view->geometry.y, |
| 5268 | 0); |
| 5269 | |
| 5270 | weston_view_geometry_dirty(esurface->view); |
| 5271 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5272 | |
| 5273 | exposay_in_flight_dec(esurface->shell); |
| 5274 | } |
| 5275 | |
| 5276 | static void |
| 5277 | exposay_animate_in(struct exposay_surface *esurface) |
| 5278 | { |
| 5279 | exposay_in_flight_inc(esurface->shell); |
| 5280 | |
| 5281 | weston_move_scale_run(esurface->view, |
| 5282 | esurface->x - esurface->view->geometry.x, |
| 5283 | esurface->y - esurface->view->geometry.y, |
| 5284 | 1.0, esurface->scale, 0, |
| 5285 | exposay_animate_in_done, esurface); |
| 5286 | } |
| 5287 | |
| 5288 | static void |
| 5289 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5290 | { |
| 5291 | struct exposay_surface *esurface = data; |
| 5292 | struct desktop_shell *shell = esurface->shell; |
| 5293 | |
| 5294 | wl_list_remove(&esurface->link); |
| 5295 | free(esurface); |
| 5296 | |
| 5297 | exposay_in_flight_dec(shell); |
| 5298 | } |
| 5299 | |
| 5300 | static void |
| 5301 | exposay_animate_out(struct exposay_surface *esurface) |
| 5302 | { |
| 5303 | exposay_in_flight_inc(esurface->shell); |
| 5304 | |
| 5305 | /* Remove the static transformation set up by |
| 5306 | * exposay_transform_in_done(). */ |
| 5307 | wl_list_remove(&esurface->transform.link); |
| 5308 | weston_view_geometry_dirty(esurface->view); |
| 5309 | |
| 5310 | weston_move_scale_run(esurface->view, |
| 5311 | esurface->x - esurface->view->geometry.x, |
| 5312 | esurface->y - esurface->view->geometry.y, |
| 5313 | 1.0, esurface->scale, 1, |
| 5314 | exposay_animate_out_done, esurface); |
| 5315 | } |
| 5316 | |
| 5317 | static void |
| 5318 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5319 | struct exposay_surface *esurface) |
| 5320 | { |
| 5321 | struct weston_view *view = NULL; |
| 5322 | |
| 5323 | if (esurface) { |
| 5324 | shell->exposay.row_current = esurface->row; |
| 5325 | shell->exposay.column_current = esurface->column; |
| 5326 | view = esurface->view; |
| 5327 | } |
| 5328 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5329 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5330 | shell->exposay.focus_current = view; |
| 5331 | } |
| 5332 | |
| 5333 | static int |
| 5334 | exposay_is_animating(struct desktop_shell *shell) |
| 5335 | { |
| 5336 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5337 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5338 | return 0; |
| 5339 | |
| 5340 | return (shell->exposay.in_flight > 0); |
| 5341 | } |
| 5342 | |
| 5343 | static void |
| 5344 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5345 | { |
| 5346 | struct exposay_surface *esurface; |
| 5347 | |
| 5348 | if (exposay_is_animating(shell)) |
| 5349 | return; |
| 5350 | |
| 5351 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5352 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5353 | continue; |
| 5354 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5355 | continue; |
| 5356 | |
| 5357 | exposay_highlight_surface(shell, esurface); |
| 5358 | return; |
| 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5363 | * aspect ratio into account really. Also needs to be notified of surface |
| 5364 | * addition and removal and adjust layout/animate accordingly. */ |
| 5365 | static enum exposay_layout_state |
| 5366 | exposay_layout(struct desktop_shell *shell) |
| 5367 | { |
| 5368 | struct workspace *workspace = shell->exposay.workspace; |
| 5369 | struct weston_compositor *compositor = shell->compositor; |
| 5370 | struct weston_output *output = get_default_output(compositor); |
| 5371 | struct weston_view *view; |
| 5372 | struct exposay_surface *esurface; |
| 5373 | int w, h; |
| 5374 | int i; |
| 5375 | int last_row_removed = 0; |
| 5376 | |
| 5377 | wl_list_init(&shell->exposay.surface_list); |
| 5378 | |
| 5379 | shell->exposay.num_surfaces = 0; |
| 5380 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5381 | if (!get_shell_surface(view->surface)) |
| 5382 | continue; |
| 5383 | shell->exposay.num_surfaces++; |
| 5384 | } |
| 5385 | |
| 5386 | if (shell->exposay.num_surfaces == 0) { |
| 5387 | shell->exposay.grid_size = 0; |
| 5388 | shell->exposay.hpadding_outer = 0; |
| 5389 | shell->exposay.vpadding_outer = 0; |
| 5390 | shell->exposay.padding_inner = 0; |
| 5391 | shell->exposay.surface_size = 0; |
| 5392 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5393 | } |
| 5394 | |
| 5395 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5396 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5397 | * around the outside and 80px internal padding between surfaces, and |
| 5398 | * maximise the area made available to surfaces after this, but only |
| 5399 | * to a maximum of 1/3rd the total output size. |
| 5400 | * |
| 5401 | * If we can't make a square grid, add one extra row at the bottom |
| 5402 | * which will have a smaller number of columns. |
| 5403 | * |
| 5404 | * XXX: Surely there has to be a better way to express this maths, |
| 5405 | * right?! |
| 5406 | */ |
| 5407 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5408 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5409 | shell->exposay.grid_size++; |
| 5410 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5411 | |
| 5412 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5413 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5414 | shell->exposay.padding_inner = 80; |
| 5415 | |
| 5416 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5417 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5418 | w /= shell->exposay.grid_size; |
| 5419 | |
| 5420 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5421 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5422 | h /= shell->exposay.grid_size; |
| 5423 | |
| 5424 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5425 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5426 | shell->exposay.surface_size = output->width / 2; |
| 5427 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5428 | shell->exposay.surface_size = output->height / 2; |
| 5429 | |
| 5430 | i = 0; |
| 5431 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5432 | int pad; |
| 5433 | |
| 5434 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5435 | |
| 5436 | if (!get_shell_surface(view->surface)) |
| 5437 | continue; |
| 5438 | |
| 5439 | esurface = malloc(sizeof(*esurface)); |
| 5440 | if (!esurface) { |
| 5441 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5442 | shell->exposay.seat); |
| 5443 | break; |
| 5444 | } |
| 5445 | |
| 5446 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5447 | esurface->shell = shell; |
| 5448 | esurface->view = view; |
| 5449 | |
| 5450 | esurface->row = i / shell->exposay.grid_size; |
| 5451 | esurface->column = i % shell->exposay.grid_size; |
| 5452 | |
| 5453 | esurface->x = shell->exposay.hpadding_outer; |
| 5454 | esurface->x += pad * esurface->column; |
| 5455 | esurface->y = shell->exposay.vpadding_outer; |
| 5456 | esurface->y += pad * esurface->row; |
| 5457 | |
| 5458 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5459 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5460 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 5461 | if (view->surface->width > view->surface->height) |
| 5462 | esurface->scale = shell->exposay.surface_size / (float) view->surface->width; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5463 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame^] | 5464 | esurface->scale = shell->exposay.surface_size / (float) view->surface->height; |
| 5465 | esurface->width = view->surface->width * esurface->scale; |
| 5466 | esurface->height = view->surface->height * esurface->scale; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5467 | |
| 5468 | if (shell->exposay.focus_current == esurface->view) |
| 5469 | exposay_highlight_surface(shell, esurface); |
| 5470 | |
| 5471 | exposay_animate_in(esurface); |
| 5472 | |
| 5473 | i++; |
| 5474 | } |
| 5475 | |
| 5476 | weston_compositor_schedule_repaint(shell->compositor); |
| 5477 | |
| 5478 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5479 | } |
| 5480 | |
| 5481 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5482 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 5483 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5484 | { |
| 5485 | struct desktop_shell *shell = |
| 5486 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5487 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5488 | weston_pointer_move(grab->pointer, x, y); |
| 5489 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5490 | exposay_pick(shell, |
| 5491 | wl_fixed_to_int(grab->pointer->x), |
| 5492 | wl_fixed_to_int(grab->pointer->y)); |
| 5493 | } |
| 5494 | |
| 5495 | static void |
| 5496 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5497 | uint32_t state_w) |
| 5498 | { |
| 5499 | struct desktop_shell *shell = |
| 5500 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5501 | struct weston_seat *seat = grab->pointer->seat; |
| 5502 | enum wl_pointer_button_state state = state_w; |
| 5503 | |
| 5504 | if (button != BTN_LEFT) |
| 5505 | return; |
| 5506 | |
| 5507 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5508 | * releasing on a different surface. */ |
| 5509 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5510 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5511 | return; |
| 5512 | } |
| 5513 | |
| 5514 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5515 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5516 | else |
| 5517 | shell->exposay.clicked = NULL; |
| 5518 | } |
| 5519 | |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5520 | static void |
| 5521 | exposay_pointer_grab_cancel(struct weston_pointer_grab *grab) |
| 5522 | { |
| 5523 | struct desktop_shell *shell = |
| 5524 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5525 | |
| 5526 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5527 | } |
| 5528 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5529 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5530 | noop_grab_focus, |
| 5531 | exposay_motion, |
| 5532 | exposay_button, |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 5533 | exposay_pointer_grab_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5534 | }; |
| 5535 | |
| 5536 | static int |
| 5537 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5538 | { |
| 5539 | struct exposay_surface *esurface; |
| 5540 | |
| 5541 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5542 | if (esurface->row != row || esurface->column != column) |
| 5543 | continue; |
| 5544 | |
| 5545 | exposay_highlight_surface(shell, esurface); |
| 5546 | return 1; |
| 5547 | } |
| 5548 | |
| 5549 | return 0; |
| 5550 | } |
| 5551 | |
| 5552 | static void |
| 5553 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5554 | uint32_t state_w) |
| 5555 | { |
| 5556 | struct weston_seat *seat = grab->keyboard->seat; |
| 5557 | struct desktop_shell *shell = |
| 5558 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5559 | enum wl_keyboard_key_state state = state_w; |
| 5560 | |
| 5561 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5562 | return; |
| 5563 | |
| 5564 | switch (key) { |
| 5565 | case KEY_ESC: |
| 5566 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5567 | break; |
| 5568 | case KEY_ENTER: |
| 5569 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5570 | break; |
| 5571 | case KEY_UP: |
| 5572 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5573 | shell->exposay.column_current); |
| 5574 | break; |
| 5575 | case KEY_DOWN: |
| 5576 | /* Special case for trying to move to the bottom row when it |
| 5577 | * has fewer items than all the others. */ |
| 5578 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5579 | shell->exposay.column_current) && |
| 5580 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5581 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5582 | (shell->exposay.num_surfaces % |
| 5583 | shell->exposay.grid_size) - 1); |
| 5584 | } |
| 5585 | break; |
| 5586 | case KEY_LEFT: |
| 5587 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5588 | shell->exposay.column_current - 1); |
| 5589 | break; |
| 5590 | case KEY_RIGHT: |
| 5591 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5592 | shell->exposay.column_current + 1); |
| 5593 | break; |
| 5594 | case KEY_TAB: |
| 5595 | /* Try to move right, then down (and to the leftmost column), |
| 5596 | * then if all else fails, to the top left. */ |
| 5597 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5598 | shell->exposay.column_current + 1) && |
| 5599 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5600 | exposay_maybe_move(shell, 0, 0); |
| 5601 | break; |
| 5602 | default: |
| 5603 | break; |
| 5604 | } |
| 5605 | } |
| 5606 | |
| 5607 | static void |
| 5608 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5609 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5610 | uint32_t mods_locked, uint32_t group) |
| 5611 | { |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5612 | struct desktop_shell *shell = |
| 5613 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5614 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 5615 | |
| 5616 | /* We want to know when mod has been pressed and released. |
| 5617 | * FIXME: There is a problem here: if mod is pressed, then a key |
| 5618 | * is pressed and released, then mod is released, we will treat that |
| 5619 | * as if only mod had been pressed and released. */ |
| 5620 | if (seat->modifier_state) { |
| 5621 | if (seat->modifier_state == shell->binding_modifier) { |
| 5622 | shell->exposay.mod_pressed = true; |
| 5623 | } else { |
| 5624 | shell->exposay.mod_invalid = true; |
| 5625 | } |
| 5626 | } else { |
| 5627 | if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid) |
| 5628 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5629 | |
| 5630 | shell->exposay.mod_invalid = false; |
| 5631 | shell->exposay.mod_pressed = false; |
| 5632 | } |
| 5633 | |
| 5634 | return; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5635 | } |
| 5636 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5637 | static void |
| 5638 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 5639 | { |
| 5640 | struct desktop_shell *shell = |
| 5641 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5642 | |
| 5643 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5644 | } |
| 5645 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5646 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5647 | exposay_key, |
| 5648 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5649 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5650 | }; |
| 5651 | |
| 5652 | /** |
| 5653 | * Called when the transition from overview -> inactive has completed. |
| 5654 | */ |
| 5655 | static enum exposay_layout_state |
| 5656 | exposay_set_inactive(struct desktop_shell *shell) |
| 5657 | { |
| 5658 | struct weston_seat *seat = shell->exposay.seat; |
| 5659 | |
| 5660 | weston_keyboard_end_grab(seat->keyboard); |
| 5661 | weston_pointer_end_grab(seat->pointer); |
| 5662 | if (seat->keyboard->input_method_resource) |
| 5663 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5664 | |
| 5665 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5666 | } |
| 5667 | |
| 5668 | /** |
| 5669 | * Begins the transition from overview to inactive. */ |
| 5670 | static enum exposay_layout_state |
| 5671 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5672 | { |
| 5673 | struct exposay_surface *esurface; |
| 5674 | |
| 5675 | /* Call activate() before we start the animations to avoid |
| 5676 | * animating back the old state and then immediately transitioning |
| 5677 | * to the new. */ |
| 5678 | if (switch_focus && shell->exposay.focus_current) |
| 5679 | activate(shell, shell->exposay.focus_current->surface, |
| 5680 | shell->exposay.seat); |
| 5681 | else if (shell->exposay.focus_prev) |
| 5682 | activate(shell, shell->exposay.focus_prev->surface, |
| 5683 | shell->exposay.seat); |
| 5684 | |
| 5685 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5686 | exposay_animate_out(esurface); |
| 5687 | weston_compositor_schedule_repaint(shell->compositor); |
| 5688 | |
| 5689 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5690 | } |
| 5691 | |
| 5692 | static enum exposay_layout_state |
| 5693 | exposay_transition_active(struct desktop_shell *shell) |
| 5694 | { |
| 5695 | struct weston_seat *seat = shell->exposay.seat; |
| 5696 | |
| 5697 | shell->exposay.workspace = get_current_workspace(shell); |
| 5698 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5699 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5700 | shell->exposay.clicked = NULL; |
| 5701 | wl_list_init(&shell->exposay.surface_list); |
| 5702 | |
| 5703 | lower_fullscreen_layer(shell); |
| 5704 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5705 | weston_keyboard_start_grab(seat->keyboard, |
| 5706 | &shell->exposay.grab_kbd); |
| 5707 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5708 | |
| 5709 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5710 | weston_pointer_start_grab(seat->pointer, |
| 5711 | &shell->exposay.grab_ptr); |
| 5712 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5713 | seat->pointer->x, seat->pointer->y); |
| 5714 | |
| 5715 | return exposay_layout(shell); |
| 5716 | } |
| 5717 | |
| 5718 | static void |
| 5719 | exposay_check_state(struct desktop_shell *shell) |
| 5720 | { |
| 5721 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5722 | int do_switch = 0; |
| 5723 | |
| 5724 | /* Don't do anything whilst animations are running, just store up |
| 5725 | * target state changes and only act on them when the animations have |
| 5726 | * completed. */ |
| 5727 | if (exposay_is_animating(shell)) |
| 5728 | return; |
| 5729 | |
| 5730 | switch (shell->exposay.state_target) { |
| 5731 | case EXPOSAY_TARGET_OVERVIEW: |
| 5732 | switch (shell->exposay.state_cur) { |
| 5733 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5734 | goto out; |
| 5735 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5736 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5737 | break; |
| 5738 | default: |
| 5739 | state_new = exposay_transition_active(shell); |
| 5740 | break; |
| 5741 | } |
| 5742 | break; |
| 5743 | |
| 5744 | case EXPOSAY_TARGET_SWITCH: |
| 5745 | do_switch = 1; /* fallthrough */ |
| 5746 | case EXPOSAY_TARGET_CANCEL: |
| 5747 | switch (shell->exposay.state_cur) { |
| 5748 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5749 | goto out; |
| 5750 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5751 | state_new = exposay_set_inactive(shell); |
| 5752 | break; |
| 5753 | default: |
| 5754 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5755 | break; |
| 5756 | } |
| 5757 | |
| 5758 | break; |
| 5759 | } |
| 5760 | |
| 5761 | out: |
| 5762 | shell->exposay.state_cur = state_new; |
| 5763 | } |
| 5764 | |
| 5765 | static void |
| 5766 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5767 | struct weston_seat *seat) |
| 5768 | { |
| 5769 | shell->exposay.state_target = state; |
| 5770 | shell->exposay.seat = seat; |
| 5771 | exposay_check_state(shell); |
| 5772 | } |
| 5773 | |
| 5774 | static void |
| 5775 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5776 | void *data) |
| 5777 | { |
| 5778 | struct desktop_shell *shell = data; |
| 5779 | |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 5780 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5781 | } |
| 5782 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5783 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5784 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5785 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5786 | { |
| 5787 | struct weston_compositor *compositor = data; |
| 5788 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5789 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5790 | |
| 5791 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5792 | * control on the primary display. We'd have to extend later if we |
| 5793 | * ever get support for setting backlights on random desktop LCD |
| 5794 | * panels though */ |
| 5795 | output = get_default_output(compositor); |
| 5796 | if (!output) |
| 5797 | return; |
| 5798 | |
| 5799 | if (!output->set_backlight) |
| 5800 | return; |
| 5801 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5802 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5803 | backlight_new = output->backlight_current - 25; |
| 5804 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5805 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5806 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5807 | if (backlight_new < 5) |
| 5808 | backlight_new = 5; |
| 5809 | if (backlight_new > 255) |
| 5810 | backlight_new = 255; |
| 5811 | |
| 5812 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5813 | output->set_backlight(output, output->backlight_current); |
| 5814 | } |
| 5815 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5816 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5817 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5818 | struct weston_seat *seat; |
| 5819 | uint32_t key[2]; |
| 5820 | int key_released[2]; |
| 5821 | }; |
| 5822 | |
| 5823 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5824 | 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] | 5825 | uint32_t key, uint32_t state) |
| 5826 | { |
| 5827 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5828 | struct weston_compositor *ec = db->seat->compositor; |
| 5829 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5830 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5831 | uint32_t serial; |
| 5832 | int send = 0, terminate = 0; |
| 5833 | int check_binding = 1; |
| 5834 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5835 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5836 | |
| 5837 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5838 | /* Do not run bindings on key releases */ |
| 5839 | check_binding = 0; |
| 5840 | |
| 5841 | for (i = 0; i < 2; i++) |
| 5842 | if (key == db->key[i]) |
| 5843 | db->key_released[i] = 1; |
| 5844 | |
| 5845 | if (db->key_released[0] && db->key_released[1]) { |
| 5846 | /* All key releases been swalled so end the grab */ |
| 5847 | terminate = 1; |
| 5848 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5849 | /* Should not swallow release of other keys */ |
| 5850 | send = 1; |
| 5851 | } |
| 5852 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5853 | /* Do not check bindings for the first press of the binding |
| 5854 | * key. This allows it to be used as a debug shortcut. |
| 5855 | * We still need to swallow this event. */ |
| 5856 | check_binding = 0; |
| 5857 | } else if (db->key[1]) { |
| 5858 | /* If we already ran a binding don't process another one since |
| 5859 | * we can't keep track of all the binding keys that were |
| 5860 | * pressed in order to swallow the release events. */ |
| 5861 | send = 1; |
| 5862 | check_binding = 0; |
| 5863 | } |
| 5864 | |
| 5865 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5866 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5867 | key, state)) { |
| 5868 | /* We ran a binding so swallow the press and keep the |
| 5869 | * grab to swallow the released too. */ |
| 5870 | send = 0; |
| 5871 | terminate = 0; |
| 5872 | db->key[1] = key; |
| 5873 | } else { |
| 5874 | /* Terminate the grab since the key pressed is not a |
| 5875 | * debug binding key. */ |
| 5876 | send = 1; |
| 5877 | terminate = 1; |
| 5878 | } |
| 5879 | } |
| 5880 | |
| 5881 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5882 | serial = wl_display_next_serial(display); |
| 5883 | resource_list = &grab->keyboard->focus_resource_list; |
| 5884 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5885 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5890 | weston_keyboard_end_grab(grab->keyboard); |
| 5891 | if (grab->keyboard->input_method_resource) |
| 5892 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5893 | free(db); |
| 5894 | } |
| 5895 | } |
| 5896 | |
| 5897 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5898 | 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] | 5899 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5900 | uint32_t mods_locked, uint32_t group) |
| 5901 | { |
| 5902 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5903 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5904 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5905 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5906 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5907 | wl_resource_for_each(resource, resource_list) { |
| 5908 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5909 | mods_latched, mods_locked, group); |
| 5910 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5911 | } |
| 5912 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5913 | static void |
| 5914 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5915 | { |
| 5916 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5917 | |
| 5918 | weston_keyboard_end_grab(grab->keyboard); |
| 5919 | free(db); |
| 5920 | } |
| 5921 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5922 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5923 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5924 | debug_binding_modifiers, |
| 5925 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5926 | }; |
| 5927 | |
| 5928 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5929 | 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] | 5930 | { |
| 5931 | struct debug_binding_grab *grab; |
| 5932 | |
| 5933 | grab = calloc(1, sizeof *grab); |
| 5934 | if (!grab) |
| 5935 | return; |
| 5936 | |
| 5937 | grab->seat = (struct weston_seat *) seat; |
| 5938 | grab->key[0] = key; |
| 5939 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5940 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5941 | } |
| 5942 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5943 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5944 | 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] | 5945 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5946 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5947 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5948 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5949 | struct desktop_shell *shell = data; |
| 5950 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5951 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5952 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5953 | focus_surface = seat->keyboard->focus; |
| 5954 | if (!focus_surface) |
| 5955 | return; |
| 5956 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5957 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5958 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5959 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5960 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5961 | |
| 5962 | /* Skip clients that we launched ourselves (the credentials of |
| 5963 | * the socketpair is ours) */ |
| 5964 | if (pid == getpid()) |
| 5965 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5966 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5967 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5968 | } |
| 5969 | |
| 5970 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5971 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5972 | uint32_t key, void *data) |
| 5973 | { |
| 5974 | struct desktop_shell *shell = data; |
| 5975 | unsigned int new_index = shell->workspaces.current; |
| 5976 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5977 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5978 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5979 | if (new_index != 0) |
| 5980 | new_index--; |
| 5981 | |
| 5982 | change_workspace(shell, new_index); |
| 5983 | } |
| 5984 | |
| 5985 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5986 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5987 | uint32_t key, void *data) |
| 5988 | { |
| 5989 | struct desktop_shell *shell = data; |
| 5990 | unsigned int new_index = shell->workspaces.current; |
| 5991 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5992 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5993 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5994 | if (new_index < shell->workspaces.num - 1) |
| 5995 | new_index++; |
| 5996 | |
| 5997 | change_workspace(shell, new_index); |
| 5998 | } |
| 5999 | |
| 6000 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6001 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6002 | uint32_t key, void *data) |
| 6003 | { |
| 6004 | struct desktop_shell *shell = data; |
| 6005 | unsigned int new_index; |
| 6006 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6007 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6008 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6009 | new_index = key - KEY_F1; |
| 6010 | if (new_index >= shell->workspaces.num) |
| 6011 | new_index = shell->workspaces.num - 1; |
| 6012 | |
| 6013 | change_workspace(shell, new_index); |
| 6014 | } |
| 6015 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6016 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6017 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6018 | uint32_t key, void *data) |
| 6019 | { |
| 6020 | struct desktop_shell *shell = data; |
| 6021 | unsigned int new_index = shell->workspaces.current; |
| 6022 | |
| 6023 | if (shell->locked) |
| 6024 | return; |
| 6025 | |
| 6026 | if (new_index != 0) |
| 6027 | new_index--; |
| 6028 | |
| 6029 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6030 | } |
| 6031 | |
| 6032 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6033 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6034 | uint32_t key, void *data) |
| 6035 | { |
| 6036 | struct desktop_shell *shell = data; |
| 6037 | unsigned int new_index = shell->workspaces.current; |
| 6038 | |
| 6039 | if (shell->locked) |
| 6040 | return; |
| 6041 | |
| 6042 | if (new_index < shell->workspaces.num - 1) |
| 6043 | new_index++; |
| 6044 | |
| 6045 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6046 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6047 | |
| 6048 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6049 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6050 | { |
| 6051 | struct shell_output *output_listener = |
| 6052 | container_of(listener, struct shell_output, destroy_listener); |
| 6053 | |
| 6054 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6055 | wl_list_remove(&output_listener->link); |
| 6056 | free(output_listener); |
| 6057 | } |
| 6058 | |
| 6059 | static void |
| 6060 | create_shell_output(struct desktop_shell *shell, |
| 6061 | struct weston_output *output) |
| 6062 | { |
| 6063 | struct shell_output *shell_output; |
| 6064 | |
| 6065 | shell_output = zalloc(sizeof *shell_output); |
| 6066 | if (shell_output == NULL) |
| 6067 | return; |
| 6068 | |
| 6069 | shell_output->output = output; |
| 6070 | shell_output->shell = shell; |
| 6071 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6072 | wl_signal_add(&output->destroy_signal, |
| 6073 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6074 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | static void |
| 6078 | handle_output_create(struct wl_listener *listener, void *data) |
| 6079 | { |
| 6080 | struct desktop_shell *shell = |
| 6081 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6082 | struct weston_output *output = (struct weston_output *)data; |
| 6083 | |
| 6084 | create_shell_output(shell, output); |
| 6085 | } |
| 6086 | |
| 6087 | static void |
| 6088 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6089 | struct desktop_shell *shell) |
| 6090 | { |
| 6091 | struct weston_output *output; |
| 6092 | |
| 6093 | wl_list_init(&shell->output_list); |
| 6094 | wl_list_for_each(output, &ec->output_list, link) |
| 6095 | create_shell_output(shell, output); |
| 6096 | |
| 6097 | shell->output_create_listener.notify = handle_output_create; |
| 6098 | wl_signal_add(&ec->output_created_signal, |
| 6099 | &shell->output_create_listener); |
| 6100 | } |
| 6101 | |
| 6102 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6103 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6104 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6105 | struct desktop_shell *shell = |
| 6106 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6107 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6108 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6109 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6110 | if (shell->child.client) |
| 6111 | wl_client_destroy(shell->child.client); |
| 6112 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6113 | wl_list_remove(&shell->idle_listener.link); |
| 6114 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6115 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 6116 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6117 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6118 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6119 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6120 | wl_list_remove(&shell_output->link); |
| 6121 | free(shell_output); |
| 6122 | } |
| 6123 | |
| 6124 | wl_list_remove(&shell->output_create_listener.link); |
| 6125 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6126 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6127 | workspace_destroy(*ws); |
| 6128 | wl_array_release(&shell->workspaces.array); |
| 6129 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6130 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6131 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6132 | free(shell); |
| 6133 | } |
| 6134 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6135 | static void |
| 6136 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6137 | { |
| 6138 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6139 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6140 | |
| 6141 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6142 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6143 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6144 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 6145 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 6146 | MODIFIER_ALT, |
| 6147 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6148 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6149 | click_to_activate_binding, |
| 6150 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6151 | weston_compositor_add_touch_binding(ec, 0, |
| 6152 | touch_to_activate_binding, |
| 6153 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6154 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6155 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6156 | surface_opacity_binding, NULL); |
| 6157 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6158 | MODIFIER_SUPER, zoom_axis_binding, |
| 6159 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6160 | |
| 6161 | /* configurable bindings */ |
| 6162 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6163 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6164 | zoom_key_binding, NULL); |
| 6165 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6166 | zoom_key_binding, NULL); |
| 6167 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6168 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6169 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6170 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6171 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6172 | |
| 6173 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6174 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6175 | rotate_binding, NULL); |
| 6176 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6177 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6178 | shell); |
| 6179 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6180 | ec); |
| 6181 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6182 | backlight_binding, ec); |
| 6183 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6184 | ec); |
| 6185 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6186 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6187 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6188 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6189 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6190 | workspace_up_binding, shell); |
| 6191 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6192 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6193 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6194 | workspace_move_surface_up_binding, |
| 6195 | shell); |
| 6196 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6197 | workspace_move_surface_down_binding, |
| 6198 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6199 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6200 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 6201 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6202 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6203 | if (shell->workspaces.num > 1) { |
| 6204 | num_workspace_bindings = shell->workspaces.num; |
| 6205 | if (num_workspace_bindings > 6) |
| 6206 | num_workspace_bindings = 6; |
| 6207 | for (i = 0; i < num_workspace_bindings; i++) |
| 6208 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6209 | workspace_f_binding, |
| 6210 | shell); |
| 6211 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6212 | |
| 6213 | /* Debug bindings */ |
| 6214 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6215 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6216 | } |
| 6217 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6218 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6219 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6220 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6221 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6222 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6223 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6224 | struct workspace **pws; |
| 6225 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6226 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6227 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6228 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6229 | if (shell == NULL) |
| 6230 | return -1; |
| 6231 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6232 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6233 | |
| 6234 | shell->destroy_listener.notify = shell_destroy; |
| 6235 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6236 | shell->idle_listener.notify = idle_handler; |
| 6237 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6238 | shell->wake_listener.notify = wake_handler; |
| 6239 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6240 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6241 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6242 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6243 | 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] | 6244 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6245 | 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] | 6246 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6247 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6248 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6249 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6250 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6251 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6252 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6253 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6254 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6255 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6256 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6257 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6258 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6259 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6260 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6261 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6262 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6263 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6264 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6265 | |
| 6266 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6267 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6268 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6269 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6270 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6271 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6272 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6273 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6274 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6275 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6276 | if (pws == NULL) |
| 6277 | return -1; |
| 6278 | |
| 6279 | *pws = workspace_create(); |
| 6280 | if (*pws == NULL) |
| 6281 | return -1; |
| 6282 | } |
| 6283 | activate_workspace(shell, 0); |
| 6284 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6285 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6286 | wl_list_init(&shell->workspaces.animation.link); |
| 6287 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6288 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6289 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6290 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6291 | return -1; |
| 6292 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6293 | if (wl_global_create(ec->wl_display, |
| 6294 | &desktop_shell_interface, 2, |
| 6295 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6296 | return -1; |
| 6297 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6298 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6299 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6300 | return -1; |
| 6301 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6302 | 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] | 6303 | shell, bind_input_panel) == NULL) |
| 6304 | return -1; |
| 6305 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6306 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6307 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6308 | return -1; |
| 6309 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6310 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6311 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6312 | setup_output_destroy_handler(ec, shell); |
| 6313 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6314 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6315 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6316 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6317 | shell->screensaver.timer = |
| 6318 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6319 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6320 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6321 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6322 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6323 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6324 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6325 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6326 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6327 | return 0; |
| 6328 | } |