Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2 | * Copyright © 2010-2012 Intel Corporation |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 3 | * Copyright © 2011-2012 Collabora, Ltd. |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4 | * Copyright © 2013 Raspberry Pi Foundation |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5 | * |
| 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
| 15 | * |
| 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 23 | */ |
| 24 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 29 | #include <stdbool.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 32 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 34 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 35 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 36 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 37 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 39 | #include "desktop-shell-server-protocol.h" |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 40 | #include "input-method-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 41 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 42 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 43 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 44 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 45 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 46 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 47 | enum animation_type { |
| 48 | ANIMATION_NONE, |
| 49 | |
| 50 | ANIMATION_ZOOM, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 51 | ANIMATION_FADE, |
| 52 | ANIMATION_DIM_LAYER, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 53 | }; |
| 54 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 55 | enum fade_type { |
| 56 | FADE_IN, |
| 57 | FADE_OUT |
| 58 | }; |
| 59 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 60 | enum exposay_target_state { |
| 61 | EXPOSAY_TARGET_OVERVIEW, /* show all windows */ |
| 62 | EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */ |
| 63 | EXPOSAY_TARGET_SWITCH, /* return to normal, switch focus */ |
| 64 | }; |
| 65 | |
| 66 | enum exposay_layout_state { |
| 67 | EXPOSAY_LAYOUT_INACTIVE = 0, /* normal desktop */ |
| 68 | EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE, /* in transition to normal */ |
| 69 | EXPOSAY_LAYOUT_OVERVIEW, /* show all windows */ |
| 70 | EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW, /* in transition to all windows */ |
| 71 | }; |
| 72 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 73 | struct focus_state { |
| 74 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 75 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 76 | struct weston_surface *keyboard_focus; |
| 77 | struct wl_list link; |
| 78 | struct wl_listener seat_destroy_listener; |
| 79 | struct wl_listener surface_destroy_listener; |
| 80 | }; |
| 81 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 82 | struct focus_surface { |
| 83 | struct weston_surface *surface; |
| 84 | struct weston_view *view; |
| 85 | struct weston_transform workspace_transform; |
| 86 | }; |
| 87 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 88 | struct workspace { |
| 89 | struct weston_layer layer; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 90 | |
| 91 | struct wl_list focus_list; |
| 92 | struct wl_listener seat_destroyed_listener; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 93 | |
| 94 | struct focus_surface *fsurf_front; |
| 95 | struct focus_surface *fsurf_back; |
| 96 | struct weston_view_animation *focus_animation; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 99 | struct input_panel_surface { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 100 | struct wl_resource *resource; |
| 101 | struct wl_signal destroy_signal; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 102 | |
| 103 | struct desktop_shell *shell; |
| 104 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 105 | struct wl_list link; |
| 106 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 107 | struct weston_view *view; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 108 | struct wl_listener surface_destroy_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 109 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 110 | struct weston_output *output; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 111 | uint32_t panel; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 114 | struct shell_output { |
| 115 | struct desktop_shell *shell; |
| 116 | struct weston_output *output; |
| 117 | struct wl_listener destroy_listener; |
| 118 | struct wl_list link; |
| 119 | }; |
| 120 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 121 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 122 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 123 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 124 | struct wl_listener idle_listener; |
| 125 | struct wl_listener wake_listener; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 126 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 127 | struct wl_listener show_input_panel_listener; |
| 128 | struct wl_listener hide_input_panel_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 129 | struct wl_listener update_input_panel_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 130 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 131 | struct weston_layer fullscreen_layer; |
| 132 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 133 | struct weston_layer background_layer; |
| 134 | struct weston_layer lock_layer; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 135 | struct weston_layer input_panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 136 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 137 | struct wl_listener pointer_focus_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 138 | struct weston_surface *grab_surface; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 139 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 140 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 141 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 142 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 143 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 144 | |
| 145 | unsigned deathcount; |
| 146 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 147 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 148 | |
| 149 | bool locked; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 150 | bool showing_input_panels; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 151 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 152 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 153 | struct { |
| 154 | struct weston_surface *surface; |
| 155 | pixman_box32_t cursor_rectangle; |
| 156 | } text_input; |
| 157 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 158 | struct weston_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 159 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 160 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 161 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 162 | struct wl_array array; |
| 163 | unsigned int current; |
| 164 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 165 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 166 | struct wl_list client_list; |
| 167 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 168 | struct weston_animation animation; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 169 | struct wl_list anim_sticky_list; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 170 | int anim_dir; |
| 171 | uint32_t anim_timestamp; |
| 172 | double anim_current; |
| 173 | struct workspace *anim_from; |
| 174 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 175 | } workspaces; |
| 176 | |
| 177 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 178 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 179 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 180 | struct wl_resource *binding; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 181 | struct weston_process process; |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 182 | struct wl_event_source *timer; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 183 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 184 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 185 | struct { |
| 186 | struct wl_resource *binding; |
| 187 | struct wl_list surfaces; |
| 188 | } input_panel; |
| 189 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 190 | struct { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 191 | struct weston_view *view; |
| 192 | struct weston_view_animation *animation; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 193 | enum fade_type type; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 194 | struct wl_event_source *startup_timer; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 195 | } fade; |
| 196 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 197 | struct exposay { |
| 198 | /* XXX: Make these exposay_surfaces. */ |
| 199 | struct weston_view *focus_prev; |
| 200 | struct weston_view *focus_current; |
| 201 | struct weston_view *clicked; |
| 202 | struct workspace *workspace; |
| 203 | struct weston_seat *seat; |
| 204 | struct wl_list surface_list; |
| 205 | |
| 206 | struct weston_keyboard_grab grab_kbd; |
| 207 | struct weston_pointer_grab grab_ptr; |
| 208 | |
| 209 | enum exposay_target_state state_target; |
| 210 | enum exposay_layout_state state_cur; |
| 211 | int in_flight; /* number of animations still running */ |
| 212 | |
| 213 | int num_surfaces; |
| 214 | int grid_size; |
| 215 | int surface_size; |
| 216 | |
| 217 | int hpadding_outer; |
| 218 | int vpadding_outer; |
| 219 | int padding_inner; |
| 220 | |
| 221 | int row_current; |
| 222 | int column_current; |
| 223 | } exposay; |
| 224 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 225 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 226 | enum animation_type win_animation_type; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 227 | enum animation_type startup_animation_type; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 228 | enum animation_type focus_animation_type; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 229 | |
| 230 | struct wl_listener output_create_listener; |
| 231 | struct wl_list output_list; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 232 | }; |
| 233 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 234 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 235 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 236 | SHELL_SURFACE_TOPLEVEL, |
| 237 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 238 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 239 | SHELL_SURFACE_MAXIMIZED, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 240 | SHELL_SURFACE_POPUP, |
| 241 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 242 | }; |
| 243 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 244 | struct ping_timer { |
| 245 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 246 | uint32_t serial; |
| 247 | }; |
| 248 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 249 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 250 | struct wl_resource *resource; |
| 251 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 252 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 253 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 254 | struct weston_view *view; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 255 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 256 | struct weston_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 257 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 258 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 259 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 260 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 261 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 262 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 263 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 264 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 265 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 266 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 267 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 268 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 269 | } rotation; |
| 270 | |
| 271 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 272 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 273 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 274 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 275 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 276 | } popup; |
| 277 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 278 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 279 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 280 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 281 | } transient; |
| 282 | |
| 283 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 284 | enum wl_shell_surface_fullscreen_method type; |
| 285 | struct weston_transform transform; /* matrix from x, y */ |
| 286 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 287 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 288 | } fullscreen; |
| 289 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 290 | struct ping_timer *ping_timer; |
| 291 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 292 | struct weston_transform workspace_transform; |
| 293 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 294 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 295 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 296 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 297 | |
| 298 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 299 | }; |
| 300 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 301 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 302 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 303 | struct shell_surface *shsurf; |
| 304 | struct wl_listener shsurf_destroy_listener; |
| 305 | }; |
| 306 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 307 | struct shell_touch_grab { |
| 308 | struct weston_touch_grab grab; |
| 309 | struct shell_surface *shsurf; |
| 310 | struct wl_listener shsurf_destroy_listener; |
| 311 | struct weston_touch *touch; |
| 312 | }; |
| 313 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 314 | struct weston_move_grab { |
| 315 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 316 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 317 | }; |
| 318 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 319 | struct weston_touch_move_grab { |
| 320 | struct shell_touch_grab base; |
| 321 | wl_fixed_t dx, dy; |
| 322 | }; |
| 323 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 324 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 325 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 326 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 327 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 328 | float x; |
| 329 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 330 | } center; |
| 331 | }; |
| 332 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 333 | struct shell_seat { |
| 334 | struct weston_seat *seat; |
| 335 | struct wl_listener seat_destroy_listener; |
| 336 | |
| 337 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 338 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 339 | struct wl_list surfaces_list; |
| 340 | struct wl_client *client; |
| 341 | int32_t initial_up; |
| 342 | } popup_grab; |
| 343 | }; |
| 344 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 345 | static void |
| 346 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 347 | struct weston_seat *seat); |
| 348 | |
| 349 | static struct workspace * |
| 350 | get_current_workspace(struct desktop_shell *shell); |
| 351 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 352 | static struct shell_surface * |
| 353 | get_shell_surface(struct weston_surface *surface); |
| 354 | |
| 355 | static struct desktop_shell * |
| 356 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 357 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 358 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 359 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 360 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 361 | static void |
| 362 | shell_fade_startup(struct desktop_shell *shell); |
| 363 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 364 | static bool |
| 365 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 366 | { |
| 367 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 368 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 369 | |
| 370 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 371 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 372 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 373 | return false; |
| 374 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 375 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 376 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 377 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 378 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 379 | } |
| 380 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 381 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 382 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 383 | { |
| 384 | struct shell_grab *grab; |
| 385 | |
| 386 | grab = container_of(listener, struct shell_grab, |
| 387 | shsurf_destroy_listener); |
| 388 | |
| 389 | grab->shsurf = NULL; |
| 390 | } |
| 391 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 392 | static struct weston_view * |
| 393 | get_default_view(struct weston_surface *surface) |
| 394 | { |
| 395 | struct shell_surface *shsurf; |
| 396 | struct weston_view *view; |
| 397 | |
| 398 | if (!surface || wl_list_empty(&surface->views)) |
| 399 | return NULL; |
| 400 | |
| 401 | shsurf = get_shell_surface(surface); |
| 402 | if (shsurf) |
| 403 | return shsurf->view; |
| 404 | |
| 405 | wl_list_for_each(view, &surface->views, surface_link) |
| 406 | if (weston_view_is_mapped(view)) |
| 407 | return view; |
| 408 | |
| 409 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 410 | } |
| 411 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 412 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 413 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 414 | |
| 415 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 416 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 417 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 418 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 419 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 420 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 421 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 422 | struct desktop_shell *shell = shsurf->shell; |
| 423 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 424 | popup_grab_end(pointer); |
| 425 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 426 | grab->grab.interface = interface; |
| 427 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 428 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 429 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 430 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 431 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 432 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 433 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 434 | if (shell->child.desktop_shell) { |
| 435 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 436 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 437 | weston_pointer_set_focus(pointer, |
| 438 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 439 | wl_fixed_from_int(0), |
| 440 | wl_fixed_from_int(0)); |
| 441 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 445 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 446 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 447 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 448 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 449 | grab->shsurf->grabbed = 0; |
| 450 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 451 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 452 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 456 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 457 | const struct weston_touch_grab_interface *interface, |
| 458 | struct shell_surface *shsurf, |
| 459 | struct weston_touch *touch) |
| 460 | { |
| 461 | struct desktop_shell *shell = shsurf->shell; |
| 462 | |
| 463 | grab->grab.interface = interface; |
| 464 | grab->shsurf = shsurf; |
| 465 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 466 | wl_signal_add(&shsurf->destroy_signal, |
| 467 | &grab->shsurf_destroy_listener); |
| 468 | |
| 469 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 470 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 471 | |
| 472 | weston_touch_start_grab(touch, &grab->grab); |
| 473 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 474 | weston_touch_set_focus(touch->seat, |
| 475 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static void |
| 479 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 480 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 481 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 482 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 483 | grab->shsurf->grabbed = 0; |
| 484 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 485 | |
| 486 | weston_touch_end_grab(grab->touch); |
| 487 | } |
| 488 | |
| 489 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 490 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 491 | struct weston_output *output); |
| 492 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 493 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 494 | get_modifier(char *modifier) |
| 495 | { |
| 496 | if (!modifier) |
| 497 | return MODIFIER_SUPER; |
| 498 | |
| 499 | if (!strcmp("ctrl", modifier)) |
| 500 | return MODIFIER_CTRL; |
| 501 | else if (!strcmp("alt", modifier)) |
| 502 | return MODIFIER_ALT; |
| 503 | else if (!strcmp("super", modifier)) |
| 504 | return MODIFIER_SUPER; |
| 505 | else |
| 506 | return MODIFIER_SUPER; |
| 507 | } |
| 508 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 509 | static enum animation_type |
| 510 | get_animation_type(char *animation) |
| 511 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 512 | if (!strcmp("zoom", animation)) |
| 513 | return ANIMATION_ZOOM; |
| 514 | else if (!strcmp("fade", animation)) |
| 515 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 516 | else if (!strcmp("dim-layer", animation)) |
| 517 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 518 | else |
| 519 | return ANIMATION_NONE; |
| 520 | } |
| 521 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 522 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 523 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 524 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 525 | struct weston_config_section *section; |
| 526 | int duration; |
| 527 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 528 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 529 | section = weston_config_get_section(shell->compositor->config, |
| 530 | "screensaver", NULL, NULL); |
| 531 | weston_config_section_get_string(section, |
| 532 | "path", &shell->screensaver.path, NULL); |
| 533 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 534 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 535 | |
| 536 | section = weston_config_get_section(shell->compositor->config, |
| 537 | "shell", NULL, NULL); |
| 538 | weston_config_section_get_string(section, |
| 539 | "binding-modifier", &s, "super"); |
| 540 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 541 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 542 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 543 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 544 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 545 | weston_config_section_get_string(section, |
| 546 | "startup-animation", &s, "fade"); |
| 547 | shell->startup_animation_type = get_animation_type(s); |
| 548 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 549 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 550 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 551 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 552 | shell->focus_animation_type = get_animation_type(s); |
| 553 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 554 | weston_config_section_get_uint(section, "num-workspaces", |
| 555 | &shell->workspaces.num, |
| 556 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 557 | } |
| 558 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 559 | static struct weston_output * |
| 560 | get_default_output(struct weston_compositor *compositor) |
| 561 | { |
| 562 | return container_of(compositor->output_list.next, |
| 563 | struct weston_output, link); |
| 564 | } |
| 565 | |
| 566 | |
| 567 | /* no-op func for checking focus surface */ |
| 568 | static void |
| 569 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, |
| 570 | int32_t width, int32_t height) |
| 571 | { |
| 572 | } |
| 573 | |
| 574 | static struct focus_surface * |
| 575 | get_focus_surface(struct weston_surface *surface) |
| 576 | { |
| 577 | if (surface->configure == focus_surface_configure) |
| 578 | return surface->configure_private; |
| 579 | else |
| 580 | return NULL; |
| 581 | } |
| 582 | |
| 583 | static bool |
| 584 | is_focus_surface (struct weston_surface *es) |
| 585 | { |
| 586 | return (es->configure == focus_surface_configure); |
| 587 | } |
| 588 | |
| 589 | static bool |
| 590 | is_focus_view (struct weston_view *view) |
| 591 | { |
| 592 | return is_focus_surface (view->surface); |
| 593 | } |
| 594 | |
| 595 | static struct focus_surface * |
| 596 | create_focus_surface(struct weston_compositor *ec, |
| 597 | struct weston_output *output) |
| 598 | { |
| 599 | struct focus_surface *fsurf = NULL; |
| 600 | struct weston_surface *surface = NULL; |
| 601 | |
| 602 | fsurf = malloc(sizeof *fsurf); |
| 603 | if (!fsurf) |
| 604 | return NULL; |
| 605 | |
| 606 | fsurf->surface = weston_surface_create(ec); |
| 607 | surface = fsurf->surface; |
| 608 | if (surface == NULL) { |
| 609 | free(fsurf); |
| 610 | return NULL; |
| 611 | } |
| 612 | |
| 613 | surface->configure = focus_surface_configure; |
| 614 | surface->output = output; |
| 615 | surface->configure_private = fsurf; |
| 616 | |
| 617 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame^] | 618 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 619 | |
| 620 | weston_view_configure(fsurf->view, output->x, output->y, |
| 621 | output->width, output->height); |
| 622 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 623 | pixman_region32_fini(&surface->opaque); |
| 624 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 625 | output->width, output->height); |
| 626 | pixman_region32_fini(&surface->input); |
| 627 | pixman_region32_init(&surface->input); |
| 628 | |
| 629 | wl_list_init(&fsurf->workspace_transform.link); |
| 630 | |
| 631 | return fsurf; |
| 632 | } |
| 633 | |
| 634 | static void |
| 635 | focus_surface_destroy(struct focus_surface *fsurf) |
| 636 | { |
| 637 | weston_surface_destroy(fsurf->surface); |
| 638 | free(fsurf); |
| 639 | } |
| 640 | |
| 641 | static void |
| 642 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 643 | { |
| 644 | struct workspace *ws = data; |
| 645 | |
| 646 | ws->focus_animation = NULL; |
| 647 | } |
| 648 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 649 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 650 | focus_state_destroy(struct focus_state *state) |
| 651 | { |
| 652 | wl_list_remove(&state->seat_destroy_listener.link); |
| 653 | wl_list_remove(&state->surface_destroy_listener.link); |
| 654 | free(state); |
| 655 | } |
| 656 | |
| 657 | static void |
| 658 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 659 | { |
| 660 | struct focus_state *state = container_of(listener, |
| 661 | struct focus_state, |
| 662 | seat_destroy_listener); |
| 663 | |
| 664 | wl_list_remove(&state->link); |
| 665 | focus_state_destroy(state); |
| 666 | } |
| 667 | |
| 668 | static void |
| 669 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 670 | { |
| 671 | struct focus_state *state = container_of(listener, |
| 672 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 673 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 674 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 675 | struct weston_surface *main_surface, *next; |
| 676 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 677 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 678 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 679 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 680 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 681 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 682 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 683 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 684 | if (is_focus_view(view)) |
| 685 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 686 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 687 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 688 | break; |
| 689 | } |
| 690 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 691 | /* if the focus was a sub-surface, activate its main surface */ |
| 692 | if (main_surface != state->keyboard_focus) |
| 693 | next = main_surface; |
| 694 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 695 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 696 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 697 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 698 | activate(shell, next, state->seat); |
| 699 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 700 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 701 | if (state->ws->focus_animation) |
| 702 | weston_view_animation_destroy(state->ws->focus_animation); |
| 703 | |
| 704 | state->ws->focus_animation = weston_fade_run( |
| 705 | state->ws->fsurf_front->view, |
| 706 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 707 | focus_animation_done, state->ws); |
| 708 | } |
| 709 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 710 | wl_list_remove(&state->link); |
| 711 | focus_state_destroy(state); |
| 712 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 716 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 717 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 718 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 719 | |
| 720 | state = malloc(sizeof *state); |
| 721 | if (state == NULL) |
| 722 | return NULL; |
| 723 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 724 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 725 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 726 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 727 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 728 | |
| 729 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 730 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 731 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 732 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 733 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 734 | |
| 735 | return state; |
| 736 | } |
| 737 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 738 | static struct focus_state * |
| 739 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 740 | { |
| 741 | struct workspace *ws = get_current_workspace(shell); |
| 742 | struct focus_state *state; |
| 743 | |
| 744 | wl_list_for_each(state, &ws->focus_list, link) |
| 745 | if (state->seat == seat) |
| 746 | break; |
| 747 | |
| 748 | if (&state->link == &ws->focus_list) |
| 749 | state = focus_state_create(seat, ws); |
| 750 | |
| 751 | return state; |
| 752 | } |
| 753 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 754 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 755 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 756 | { |
| 757 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 758 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 759 | |
| 760 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 761 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 762 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 763 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
| 767 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 768 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 769 | struct weston_seat *seat) |
| 770 | { |
| 771 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 772 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 773 | |
| 774 | wl_list_for_each(state, &ws->focus_list, link) { |
| 775 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 776 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 777 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 778 | return; |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | static void |
| 784 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 785 | struct weston_surface *surface) |
| 786 | { |
| 787 | struct focus_state *state; |
| 788 | |
| 789 | wl_list_for_each(state, &ws->focus_list, link) |
| 790 | if (state->keyboard_focus == surface) |
| 791 | state->keyboard_focus = NULL; |
| 792 | } |
| 793 | |
| 794 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 795 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 796 | struct weston_view *from, struct weston_view *to) |
| 797 | { |
| 798 | struct weston_output *output; |
| 799 | bool focus_surface_created = false; |
| 800 | |
| 801 | /* FIXME: Only support dim animation using two layers */ |
| 802 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 803 | return; |
| 804 | |
| 805 | output = get_default_output(shell->compositor); |
| 806 | if (ws->fsurf_front == NULL && (from || to)) { |
| 807 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 808 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 809 | ws->fsurf_front->view->alpha = 0.0; |
| 810 | ws->fsurf_back->view->alpha = 0.0; |
| 811 | focus_surface_created = true; |
| 812 | } else { |
| 813 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 814 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 815 | } |
| 816 | |
| 817 | if (ws->focus_animation) { |
| 818 | weston_view_animation_destroy(ws->focus_animation); |
| 819 | ws->focus_animation = NULL; |
| 820 | } |
| 821 | |
| 822 | if (to) |
| 823 | wl_list_insert(&to->layer_link, |
| 824 | &ws->fsurf_front->view->layer_link); |
| 825 | else if (from) |
| 826 | wl_list_insert(&ws->layer.view_list, |
| 827 | &ws->fsurf_front->view->layer_link); |
| 828 | |
| 829 | if (focus_surface_created) { |
| 830 | ws->focus_animation = weston_fade_run( |
| 831 | ws->fsurf_front->view, |
| 832 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 833 | focus_animation_done, ws); |
| 834 | } else if (from) { |
| 835 | wl_list_insert(&from->layer_link, |
| 836 | &ws->fsurf_back->view->layer_link); |
| 837 | ws->focus_animation = weston_stable_fade_run( |
| 838 | ws->fsurf_front->view, 0.0, |
| 839 | ws->fsurf_back->view, 0.6, |
| 840 | focus_animation_done, ws); |
| 841 | } else if (to) { |
| 842 | wl_list_insert(&ws->layer.view_list, |
| 843 | &ws->fsurf_back->view->layer_link); |
| 844 | ws->focus_animation = weston_stable_fade_run( |
| 845 | ws->fsurf_front->view, 0.0, |
| 846 | ws->fsurf_back->view, 0.6, |
| 847 | focus_animation_done, ws); |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 852 | workspace_destroy(struct workspace *ws) |
| 853 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 854 | struct focus_state *state, *next; |
| 855 | |
| 856 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 857 | focus_state_destroy(state); |
| 858 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 859 | if (ws->fsurf_front) |
| 860 | focus_surface_destroy(ws->fsurf_front); |
| 861 | if (ws->fsurf_back) |
| 862 | focus_surface_destroy(ws->fsurf_back); |
| 863 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 864 | free(ws); |
| 865 | } |
| 866 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 867 | static void |
| 868 | seat_destroyed(struct wl_listener *listener, void *data) |
| 869 | { |
| 870 | struct weston_seat *seat = data; |
| 871 | struct focus_state *state, *next; |
| 872 | struct workspace *ws = container_of(listener, |
| 873 | struct workspace, |
| 874 | seat_destroyed_listener); |
| 875 | |
| 876 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 877 | if (state->seat == seat) |
| 878 | wl_list_remove(&state->link); |
| 879 | } |
| 880 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 881 | static struct workspace * |
| 882 | workspace_create(void) |
| 883 | { |
| 884 | struct workspace *ws = malloc(sizeof *ws); |
| 885 | if (ws == NULL) |
| 886 | return NULL; |
| 887 | |
| 888 | weston_layer_init(&ws->layer, NULL); |
| 889 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 890 | wl_list_init(&ws->focus_list); |
| 891 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 892 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 893 | ws->fsurf_front = NULL; |
| 894 | ws->fsurf_back = NULL; |
| 895 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 896 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 897 | return ws; |
| 898 | } |
| 899 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 900 | static int |
| 901 | workspace_is_empty(struct workspace *ws) |
| 902 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 903 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 904 | } |
| 905 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 906 | static struct workspace * |
| 907 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 908 | { |
| 909 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 910 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 911 | pws += index; |
| 912 | return *pws; |
| 913 | } |
| 914 | |
| 915 | static struct workspace * |
| 916 | get_current_workspace(struct desktop_shell *shell) |
| 917 | { |
| 918 | return get_workspace(shell, shell->workspaces.current); |
| 919 | } |
| 920 | |
| 921 | static void |
| 922 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 923 | { |
| 924 | struct workspace *ws; |
| 925 | |
| 926 | ws = get_workspace(shell, index); |
| 927 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 928 | |
| 929 | shell->workspaces.current = index; |
| 930 | } |
| 931 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 932 | static unsigned int |
| 933 | get_output_height(struct weston_output *output) |
| 934 | { |
| 935 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 936 | } |
| 937 | |
| 938 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 939 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 940 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 941 | struct weston_transform *transform; |
| 942 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 943 | if (is_focus_view(view)) { |
| 944 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 945 | transform = &fsurf->workspace_transform; |
| 946 | } else { |
| 947 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 948 | transform = &shsurf->workspace_transform; |
| 949 | } |
| 950 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 951 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 952 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 953 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 954 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 955 | weston_matrix_init(&transform->matrix); |
| 956 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 957 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 958 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static void |
| 962 | workspace_translate_out(struct workspace *ws, double fraction) |
| 963 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 964 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 965 | unsigned int height; |
| 966 | double d; |
| 967 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 968 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 969 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 970 | d = height * fraction; |
| 971 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 972 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
| 976 | static void |
| 977 | workspace_translate_in(struct workspace *ws, double fraction) |
| 978 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 979 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 980 | unsigned int height; |
| 981 | double d; |
| 982 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 983 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 984 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 985 | |
| 986 | if (fraction > 0) |
| 987 | d = -(height - height * fraction); |
| 988 | else |
| 989 | d = height + height * fraction; |
| 990 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 991 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
| 995 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 996 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 997 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 998 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 999 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1000 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1001 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1002 | shell->workspaces.current, |
| 1003 | shell->workspaces.num); |
| 1004 | } |
| 1005 | |
| 1006 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1007 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1008 | unsigned int index, |
| 1009 | struct workspace *from, |
| 1010 | struct workspace *to) |
| 1011 | { |
| 1012 | shell->workspaces.current = index; |
| 1013 | |
| 1014 | shell->workspaces.anim_to = to; |
| 1015 | shell->workspaces.anim_from = from; |
| 1016 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1017 | shell->workspaces.anim_timestamp = 0; |
| 1018 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1019 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | static void |
| 1023 | workspace_deactivate_transforms(struct workspace *ws) |
| 1024 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1025 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1026 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1027 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1028 | 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] | 1029 | if (is_focus_view(view)) { |
| 1030 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1031 | transform = &fsurf->workspace_transform; |
| 1032 | } else { |
| 1033 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1034 | transform = &shsurf->workspace_transform; |
| 1035 | } |
| 1036 | |
| 1037 | if (!wl_list_empty(&transform->link)) { |
| 1038 | wl_list_remove(&transform->link); |
| 1039 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1040 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1041 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | static void |
| 1046 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1047 | struct workspace *from, |
| 1048 | struct workspace *to) |
| 1049 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1050 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1051 | |
| 1052 | wl_list_remove(&shell->workspaces.animation.link); |
| 1053 | workspace_deactivate_transforms(from); |
| 1054 | workspace_deactivate_transforms(to); |
| 1055 | shell->workspaces.anim_to = NULL; |
| 1056 | |
| 1057 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1058 | } |
| 1059 | |
| 1060 | static void |
| 1061 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1062 | struct weston_output *output, uint32_t msecs) |
| 1063 | { |
| 1064 | struct desktop_shell *shell = |
| 1065 | container_of(animation, struct desktop_shell, |
| 1066 | workspaces.animation); |
| 1067 | struct workspace *from = shell->workspaces.anim_from; |
| 1068 | struct workspace *to = shell->workspaces.anim_to; |
| 1069 | uint32_t t; |
| 1070 | double x, y; |
| 1071 | |
| 1072 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1073 | finish_workspace_change_animation(shell, from, to); |
| 1074 | return; |
| 1075 | } |
| 1076 | |
| 1077 | if (shell->workspaces.anim_timestamp == 0) { |
| 1078 | if (shell->workspaces.anim_current == 0.0) |
| 1079 | shell->workspaces.anim_timestamp = msecs; |
| 1080 | else |
| 1081 | shell->workspaces.anim_timestamp = |
| 1082 | msecs - |
| 1083 | /* Invers of movement function 'y' below. */ |
| 1084 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1085 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1086 | M_2_PI); |
| 1087 | } |
| 1088 | |
| 1089 | t = msecs - shell->workspaces.anim_timestamp; |
| 1090 | |
| 1091 | /* |
| 1092 | * x = [0, π/2] |
| 1093 | * y(x) = sin(x) |
| 1094 | */ |
| 1095 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1096 | y = sin(x); |
| 1097 | |
| 1098 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1099 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1100 | |
| 1101 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1102 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1103 | shell->workspaces.anim_current = y; |
| 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 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1107 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1108 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | static void |
| 1112 | animate_workspace_change(struct desktop_shell *shell, |
| 1113 | unsigned int index, |
| 1114 | struct workspace *from, |
| 1115 | struct workspace *to) |
| 1116 | { |
| 1117 | struct weston_output *output; |
| 1118 | |
| 1119 | int dir; |
| 1120 | |
| 1121 | if (index > shell->workspaces.current) |
| 1122 | dir = -1; |
| 1123 | else |
| 1124 | dir = 1; |
| 1125 | |
| 1126 | shell->workspaces.current = index; |
| 1127 | |
| 1128 | shell->workspaces.anim_dir = dir; |
| 1129 | shell->workspaces.anim_from = from; |
| 1130 | shell->workspaces.anim_to = to; |
| 1131 | shell->workspaces.anim_current = 0.0; |
| 1132 | shell->workspaces.anim_timestamp = 0; |
| 1133 | |
| 1134 | output = container_of(shell->compositor->output_list.next, |
| 1135 | struct weston_output, link); |
| 1136 | wl_list_insert(&output->animation_list, |
| 1137 | &shell->workspaces.animation.link); |
| 1138 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1139 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1140 | |
| 1141 | workspace_translate_in(to, 0); |
| 1142 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1143 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1144 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1145 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1146 | } |
| 1147 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1148 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1149 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1150 | struct workspace *from, struct workspace *to) |
| 1151 | { |
| 1152 | shell->workspaces.current = index; |
| 1153 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1154 | wl_list_remove(&from->layer.link); |
| 1155 | } |
| 1156 | |
| 1157 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1158 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1159 | { |
| 1160 | struct workspace *from; |
| 1161 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1162 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1163 | |
| 1164 | if (index == shell->workspaces.current) |
| 1165 | return; |
| 1166 | |
| 1167 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1168 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1169 | return; |
| 1170 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1171 | from = get_current_workspace(shell); |
| 1172 | to = get_workspace(shell, index); |
| 1173 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1174 | if (shell->workspaces.anim_from == to && |
| 1175 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1176 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1177 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1178 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1179 | return; |
| 1180 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1181 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | if (shell->workspaces.anim_to != NULL) |
| 1183 | finish_workspace_change_animation(shell, |
| 1184 | shell->workspaces.anim_from, |
| 1185 | shell->workspaces.anim_to); |
| 1186 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1187 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1188 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1189 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1190 | wl_list_for_each(state, &from->focus_list, link) |
| 1191 | if (state->keyboard_focus) |
| 1192 | animate_focus_change(shell, from, |
| 1193 | get_default_view(state->keyboard_focus), NULL); |
| 1194 | |
| 1195 | wl_list_for_each(state, &to->focus_list, link) |
| 1196 | if (state->keyboard_focus) |
| 1197 | animate_focus_change(shell, to, |
| 1198 | NULL, get_default_view(state->keyboard_focus)); |
| 1199 | } |
| 1200 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1201 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1202 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1203 | else |
| 1204 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1205 | |
| 1206 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1207 | } |
| 1208 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1209 | static bool |
| 1210 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1211 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1212 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1213 | struct wl_list *e; |
| 1214 | |
| 1215 | if (wl_list_empty(list)) |
| 1216 | return false; |
| 1217 | |
| 1218 | e = list->next; |
| 1219 | |
| 1220 | if (e->next != list) |
| 1221 | return false; |
| 1222 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1223 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1227 | move_view_to_workspace(struct desktop_shell *shell, |
| 1228 | struct weston_view *view, |
| 1229 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1230 | { |
| 1231 | struct workspace *from; |
| 1232 | struct workspace *to; |
| 1233 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1234 | struct weston_surface *focus; |
| 1235 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1236 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1237 | |
| 1238 | if (workspace == shell->workspaces.current) |
| 1239 | return; |
| 1240 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1241 | if (workspace >= shell->workspaces.num) |
| 1242 | workspace = shell->workspaces.num - 1; |
| 1243 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1244 | from = get_current_workspace(shell); |
| 1245 | to = get_workspace(shell, workspace); |
| 1246 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1247 | wl_list_remove(&view->layer_link); |
| 1248 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1249 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1250 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1251 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1252 | if (!seat->keyboard) |
| 1253 | continue; |
| 1254 | |
| 1255 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1256 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1257 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1258 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1259 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1260 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1264 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1265 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1266 | unsigned int index) |
| 1267 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1268 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1269 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1270 | struct shell_surface *shsurf; |
| 1271 | struct workspace *from; |
| 1272 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1273 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1274 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1275 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1276 | view = get_default_view(surface); |
| 1277 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1278 | index == shell->workspaces.current || |
| 1279 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1280 | return; |
| 1281 | |
| 1282 | from = get_current_workspace(shell); |
| 1283 | to = get_workspace(shell, index); |
| 1284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1285 | wl_list_remove(&view->layer_link); |
| 1286 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1287 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1288 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1289 | drop_focus_state(shell, from, surface); |
| 1290 | |
| 1291 | if (shell->workspaces.anim_from == to && |
| 1292 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1293 | wl_list_remove(&to->layer.link); |
| 1294 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1295 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1296 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1297 | broadcast_current_workspace_state(shell); |
| 1298 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1299 | return; |
| 1300 | } |
| 1301 | |
| 1302 | if (shell->workspaces.anim_to != NULL) |
| 1303 | finish_workspace_change_animation(shell, |
| 1304 | shell->workspaces.anim_from, |
| 1305 | shell->workspaces.anim_to); |
| 1306 | |
| 1307 | if (workspace_is_empty(from) && |
| 1308 | workspace_has_only(to, surface)) |
| 1309 | update_workspace(shell, index, from, to); |
| 1310 | else { |
| 1311 | shsurf = get_shell_surface(surface); |
| 1312 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 1313 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1314 | &shsurf->workspace_transform.link); |
| 1315 | |
| 1316 | animate_workspace_change(shell, index, from, to); |
| 1317 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1318 | |
| 1319 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1320 | |
| 1321 | state = ensure_focus_state(shell, seat); |
| 1322 | if (state != NULL) |
| 1323 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | static void |
| 1327 | workspace_manager_move_surface(struct wl_client *client, |
| 1328 | struct wl_resource *resource, |
| 1329 | struct wl_resource *surface_resource, |
| 1330 | uint32_t workspace) |
| 1331 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1332 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1333 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1334 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1335 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1336 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1337 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1338 | main_surface = weston_surface_get_main_surface(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1339 | view = get_default_view(main_surface); |
| 1340 | if (!view) |
| 1341 | return; |
| 1342 | move_view_to_workspace(shell, view, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1346 | workspace_manager_move_surface, |
| 1347 | }; |
| 1348 | |
| 1349 | static void |
| 1350 | unbind_resource(struct wl_resource *resource) |
| 1351 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1352 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | static void |
| 1356 | bind_workspace_manager(struct wl_client *client, |
| 1357 | void *data, uint32_t version, uint32_t id) |
| 1358 | { |
| 1359 | struct desktop_shell *shell = data; |
| 1360 | struct wl_resource *resource; |
| 1361 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1362 | resource = wl_resource_create(client, |
| 1363 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1364 | |
| 1365 | if (resource == NULL) { |
| 1366 | weston_log("couldn't add workspace manager object"); |
| 1367 | return; |
| 1368 | } |
| 1369 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1370 | wl_resource_set_implementation(resource, |
| 1371 | &workspace_manager_implementation, |
| 1372 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1373 | wl_list_insert(&shell->workspaces.client_list, |
| 1374 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1375 | |
| 1376 | workspace_manager_send_state(resource, |
| 1377 | shell->workspaces.current, |
| 1378 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1379 | } |
| 1380 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1381 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1382 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1383 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1384 | { |
| 1385 | } |
| 1386 | |
| 1387 | static void |
| 1388 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1389 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1390 | struct weston_touch_move_grab *move = |
| 1391 | (struct weston_touch_move_grab *) container_of( |
| 1392 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1393 | |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1394 | if (grab->touch->seat->num_tp == 0) { |
| 1395 | shell_touch_grab_end(&move->base); |
| 1396 | free(move); |
| 1397 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | static void |
| 1401 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1402 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1403 | { |
| 1404 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1405 | struct shell_surface *shsurf = move->base.shsurf; |
| 1406 | struct weston_surface *es; |
| 1407 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1408 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1409 | |
| 1410 | if (!shsurf) |
| 1411 | return; |
| 1412 | |
| 1413 | es = shsurf->surface; |
| 1414 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1415 | weston_view_configure(shsurf->view, dx, dy, |
| 1416 | shsurf->view->geometry.width, |
| 1417 | shsurf->view->geometry.height); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1418 | |
| 1419 | weston_compositor_schedule_repaint(es->compositor); |
| 1420 | } |
| 1421 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1422 | static void |
| 1423 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1424 | { |
| 1425 | struct weston_touch_move_grab *move = |
| 1426 | (struct weston_touch_move_grab *) container_of( |
| 1427 | grab, struct shell_touch_grab, grab); |
| 1428 | |
| 1429 | shell_touch_grab_end(&move->base); |
| 1430 | free(move); |
| 1431 | } |
| 1432 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1433 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1434 | touch_move_grab_down, |
| 1435 | touch_move_grab_up, |
| 1436 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1437 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1438 | }; |
| 1439 | |
| 1440 | static int |
| 1441 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1442 | { |
| 1443 | struct weston_touch_move_grab *move; |
| 1444 | |
| 1445 | if (!shsurf) |
| 1446 | return -1; |
| 1447 | |
| 1448 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1449 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1450 | if (shsurf->grabbed) |
| 1451 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1452 | |
| 1453 | move = malloc(sizeof *move); |
| 1454 | if (!move) |
| 1455 | return -1; |
| 1456 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1457 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1458 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1459 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1460 | seat->touch->grab_y; |
| 1461 | |
| 1462 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1463 | seat->touch); |
| 1464 | |
| 1465 | return 0; |
| 1466 | } |
| 1467 | |
| 1468 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1469 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1470 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1474 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1475 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1476 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1477 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1478 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1479 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1480 | int dx, dy; |
| 1481 | |
| 1482 | weston_pointer_move(pointer, x, y); |
| 1483 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1484 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1485 | |
| 1486 | if (!shsurf) |
| 1487 | return; |
| 1488 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1489 | weston_view_configure(shsurf->view, dx, dy, |
| 1490 | shsurf->view->geometry.width, |
| 1491 | shsurf->view->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1492 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1493 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1497 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1498 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1499 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1500 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1501 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1502 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1503 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1504 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1505 | if (pointer->button_count == 0 && |
| 1506 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1507 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1508 | free(grab); |
| 1509 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1510 | } |
| 1511 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1512 | static void |
| 1513 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1514 | { |
| 1515 | struct shell_grab *shell_grab = |
| 1516 | container_of(grab, struct shell_grab, grab); |
| 1517 | |
| 1518 | shell_grab_end(shell_grab); |
| 1519 | free(grab); |
| 1520 | } |
| 1521 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1522 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1523 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1524 | move_grab_motion, |
| 1525 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1526 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1527 | }; |
| 1528 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1529 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1530 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1531 | { |
| 1532 | struct weston_move_grab *move; |
| 1533 | |
| 1534 | if (!shsurf) |
| 1535 | return -1; |
| 1536 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1537 | if (shsurf->grabbed) |
| 1538 | return 0; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1539 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1540 | return 0; |
| 1541 | |
| 1542 | move = malloc(sizeof *move); |
| 1543 | if (!move) |
| 1544 | return -1; |
| 1545 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1546 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1547 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1548 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1549 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1550 | |
| 1551 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1552 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1553 | |
| 1554 | return 0; |
| 1555 | } |
| 1556 | |
| 1557 | static void |
| 1558 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1559 | struct wl_resource *seat_resource, uint32_t serial) |
| 1560 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1561 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1562 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1563 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1564 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1565 | if (seat->pointer && |
| 1566 | seat->pointer->button_count > 0 && |
| 1567 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1568 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1569 | if ((surface == shsurf->surface) && |
| 1570 | (surface_move(shsurf, seat) < 0)) |
| 1571 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1572 | } else if (seat->touch && |
| 1573 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1574 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1575 | if ((surface == shsurf->surface) && |
| 1576 | (surface_touch_move(shsurf, seat) < 0)) |
| 1577 | wl_resource_post_no_memory(resource); |
| 1578 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | struct weston_resize_grab { |
| 1582 | struct shell_grab base; |
| 1583 | uint32_t edges; |
| 1584 | int32_t width, height; |
| 1585 | }; |
| 1586 | |
| 1587 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1588 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1589 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1590 | { |
| 1591 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1592 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1593 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1594 | int32_t width, height; |
| 1595 | wl_fixed_t from_x, from_y; |
| 1596 | wl_fixed_t to_x, to_y; |
| 1597 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1598 | weston_pointer_move(pointer, x, y); |
| 1599 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1600 | if (!shsurf) |
| 1601 | return; |
| 1602 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1603 | weston_view_from_global_fixed(shsurf->view, |
| 1604 | pointer->grab_x, pointer->grab_y, |
| 1605 | &from_x, &from_y); |
| 1606 | weston_view_from_global_fixed(shsurf->view, |
| 1607 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1608 | |
| 1609 | width = resize->width; |
| 1610 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1611 | width += wl_fixed_to_int(from_x - to_x); |
| 1612 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1613 | width += wl_fixed_to_int(to_x - from_x); |
| 1614 | } |
| 1615 | |
| 1616 | height = resize->height; |
| 1617 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1618 | height += wl_fixed_to_int(from_y - to_y); |
| 1619 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1620 | height += wl_fixed_to_int(to_y - from_y); |
| 1621 | } |
| 1622 | |
| 1623 | shsurf->client->send_configure(shsurf->surface, |
| 1624 | resize->edges, width, height); |
| 1625 | } |
| 1626 | |
| 1627 | static void |
| 1628 | send_configure(struct weston_surface *surface, |
| 1629 | uint32_t edges, int32_t width, int32_t height) |
| 1630 | { |
| 1631 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1632 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1633 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1634 | edges, width, height); |
| 1635 | } |
| 1636 | |
| 1637 | static const struct weston_shell_client shell_client = { |
| 1638 | send_configure |
| 1639 | }; |
| 1640 | |
| 1641 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1642 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1643 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1644 | { |
| 1645 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1646 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1647 | enum wl_pointer_button_state state = state_w; |
| 1648 | |
| 1649 | if (pointer->button_count == 0 && |
| 1650 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1651 | shell_grab_end(&resize->base); |
| 1652 | free(grab); |
| 1653 | } |
| 1654 | } |
| 1655 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1656 | static void |
| 1657 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1658 | { |
| 1659 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1660 | |
| 1661 | shell_grab_end(&resize->base); |
| 1662 | free(grab); |
| 1663 | } |
| 1664 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1665 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1666 | noop_grab_focus, |
| 1667 | resize_grab_motion, |
| 1668 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1669 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1670 | }; |
| 1671 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1672 | /* |
| 1673 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1674 | * in the surface coordinates system. */ |
| 1675 | static void |
| 1676 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1677 | int32_t *y, int32_t *w, int32_t *h) { |
| 1678 | pixman_region32_t region; |
| 1679 | pixman_box32_t *box; |
| 1680 | struct weston_subsurface *subsurface; |
| 1681 | |
| 1682 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1683 | surface->width, |
| 1684 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1685 | |
| 1686 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1687 | pixman_region32_union_rect(®ion, ®ion, |
| 1688 | subsurface->position.x, |
| 1689 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1690 | subsurface->surface->width, |
| 1691 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | box = pixman_region32_extents(®ion); |
| 1695 | if (x) |
| 1696 | *x = box->x1; |
| 1697 | if (y) |
| 1698 | *y = box->y1; |
| 1699 | if (w) |
| 1700 | *w = box->x2 - box->x1; |
| 1701 | if (h) |
| 1702 | *h = box->y2 - box->y1; |
| 1703 | |
| 1704 | pixman_region32_fini(®ion); |
| 1705 | } |
| 1706 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1707 | static int |
| 1708 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1709 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1710 | { |
| 1711 | struct weston_resize_grab *resize; |
| 1712 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1713 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1714 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1715 | return 0; |
| 1716 | |
| 1717 | if (edges == 0 || edges > 15 || |
| 1718 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1719 | return 0; |
| 1720 | |
| 1721 | resize = malloc(sizeof *resize); |
| 1722 | if (!resize) |
| 1723 | return -1; |
| 1724 | |
| 1725 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1726 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1727 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1728 | |
| 1729 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1730 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1731 | |
| 1732 | return 0; |
| 1733 | } |
| 1734 | |
| 1735 | static void |
| 1736 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1737 | struct wl_resource *seat_resource, uint32_t serial, |
| 1738 | uint32_t edges) |
| 1739 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1740 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1741 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1742 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1743 | |
| 1744 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1745 | return; |
| 1746 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1747 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1748 | if (seat->pointer->button_count == 0 || |
| 1749 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1750 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1751 | return; |
| 1752 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1753 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1754 | wl_resource_post_no_memory(resource); |
| 1755 | } |
| 1756 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1757 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1758 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1759 | |
| 1760 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1761 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1762 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1763 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1764 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1765 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1766 | wl_fixed_t sx, sy; |
| 1767 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1768 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1769 | pointer->x, pointer->y, |
| 1770 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1771 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1772 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1773 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1777 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1778 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1779 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1780 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1781 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1782 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1783 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1784 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1785 | uint32_t time, uint32_t button, uint32_t state) |
| 1786 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1787 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1788 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1789 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1790 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1791 | if (shsurf && button == BTN_LEFT && state) { |
| 1792 | activate(shsurf->shell, shsurf->surface, seat); |
| 1793 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1794 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1795 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1796 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1797 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1798 | } |
| 1799 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1800 | static void |
| 1801 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1802 | { |
| 1803 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1804 | |
| 1805 | shell_grab_end(grab); |
| 1806 | free(grab); |
| 1807 | } |
| 1808 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1809 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1810 | busy_cursor_grab_focus, |
| 1811 | busy_cursor_grab_motion, |
| 1812 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1813 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1814 | }; |
| 1815 | |
| 1816 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1817 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1818 | { |
| 1819 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1820 | |
| 1821 | grab = malloc(sizeof *grab); |
| 1822 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1823 | return; |
| 1824 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1825 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1826 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1827 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1828 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1829 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1830 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1831 | { |
| 1832 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1833 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1834 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1835 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1836 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1837 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1838 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1839 | } |
| 1840 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1841 | static void |
| 1842 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1843 | { |
| 1844 | if (!shsurf || !shsurf->ping_timer) |
| 1845 | return; |
| 1846 | |
| 1847 | if (shsurf->ping_timer->source) |
| 1848 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1849 | |
| 1850 | free(shsurf->ping_timer); |
| 1851 | shsurf->ping_timer = NULL; |
| 1852 | } |
| 1853 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1854 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1855 | ping_timeout_handler(void *data) |
| 1856 | { |
| 1857 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1858 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1859 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1860 | /* Client is not responding */ |
| 1861 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1862 | |
| 1863 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1864 | if (seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1865 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1866 | |
| 1867 | return 1; |
| 1868 | } |
| 1869 | |
| 1870 | static void |
| 1871 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1872 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1873 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1874 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1875 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1876 | |
| 1877 | if (!shsurf) |
| 1878 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1879 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1880 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1881 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1882 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1883 | return; |
| 1884 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1885 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1886 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1887 | if (!shsurf->ping_timer) |
| 1888 | return; |
| 1889 | |
| 1890 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1891 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1892 | shsurf->ping_timer->source = |
| 1893 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1894 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1895 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1896 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1897 | } |
| 1898 | } |
| 1899 | |
| 1900 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1901 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1902 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1903 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1904 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1905 | struct weston_compositor *compositor; |
| 1906 | struct shell_surface *shsurf; |
| 1907 | uint32_t serial; |
| 1908 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1909 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1910 | return; |
| 1911 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1912 | compositor = view->surface->compositor; |
| 1913 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1914 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1915 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1916 | set_busy_cursor(shsurf, pointer); |
| 1917 | } else { |
| 1918 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1919 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1924 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1925 | { |
| 1926 | struct wl_listener *listener; |
| 1927 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1928 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1929 | return; |
| 1930 | |
| 1931 | listener = malloc(sizeof *listener); |
| 1932 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1933 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1937 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1938 | uint32_t serial) |
| 1939 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1940 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1941 | struct weston_seat *seat; |
| 1942 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1943 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1944 | if (shsurf->ping_timer == NULL) |
| 1945 | /* Just ignore unsolicited pong. */ |
| 1946 | return; |
| 1947 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1948 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1949 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1950 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1951 | if(seat->pointer) |
| 1952 | end_busy_cursor(shsurf, seat->pointer); |
| 1953 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1954 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1955 | } |
| 1956 | } |
| 1957 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1958 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1959 | set_title(struct shell_surface *shsurf, const char *title) |
| 1960 | { |
| 1961 | free(shsurf->title); |
| 1962 | shsurf->title = strdup(title); |
| 1963 | } |
| 1964 | |
| 1965 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1966 | shell_surface_set_title(struct wl_client *client, |
| 1967 | struct wl_resource *resource, const char *title) |
| 1968 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1969 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1970 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1971 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | static void |
| 1975 | shell_surface_set_class(struct wl_client *client, |
| 1976 | struct wl_resource *resource, const char *class) |
| 1977 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1978 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1979 | |
| 1980 | free(shsurf->class); |
| 1981 | shsurf->class = strdup(class); |
| 1982 | } |
| 1983 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1984 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1985 | restore_output_mode(struct weston_output *output) |
| 1986 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1987 | if (output->current_mode != output->original_mode || |
| 1988 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1989 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1990 | output->original_mode, |
| 1991 | output->original_scale, |
| 1992 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | static void |
| 1996 | restore_all_output_modes(struct weston_compositor *compositor) |
| 1997 | { |
| 1998 | struct weston_output *output; |
| 1999 | |
| 2000 | wl_list_for_each(output, &compositor->output_list, link) |
| 2001 | restore_output_mode(output); |
| 2002 | } |
| 2003 | |
| 2004 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2005 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 2006 | { |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2007 | struct workspace *ws; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2008 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2009 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2010 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2011 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2012 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2013 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2014 | shsurf->fullscreen.framerate = 0; |
| 2015 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2016 | wl_list_init(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2017 | if (shsurf->fullscreen.black_view) |
| 2018 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2019 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2020 | shsurf->fullscreen_output = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2021 | weston_view_set_position(shsurf->view, |
| 2022 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2023 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2024 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2025 | &shsurf->rotation.transform.link); |
| 2026 | shsurf->saved_rotation_valid = false; |
| 2027 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2028 | |
| 2029 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2030 | wl_list_remove(&shsurf->view->layer_link); |
| 2031 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2032 | } |
| 2033 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2034 | static void |
| 2035 | shell_unset_maximized(struct shell_surface *shsurf) |
| 2036 | { |
| 2037 | struct workspace *ws; |
| 2038 | /* undo all maximized things here */ |
| 2039 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2040 | weston_view_set_position(shsurf->view, |
| 2041 | shsurf->saved_x, |
| 2042 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2043 | |
| 2044 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2045 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2046 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2047 | shsurf->saved_rotation_valid = false; |
| 2048 | } |
| 2049 | |
| 2050 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2051 | wl_list_remove(&shsurf->view->layer_link); |
| 2052 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2053 | } |
| 2054 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2055 | static int |
| 2056 | reset_shell_surface_type(struct shell_surface *surface) |
| 2057 | { |
| 2058 | switch (surface->type) { |
| 2059 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2060 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2061 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2062 | case SHELL_SURFACE_MAXIMIZED: |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2063 | shell_unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2064 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2065 | case SHELL_SURFACE_NONE: |
| 2066 | case SHELL_SURFACE_TOPLEVEL: |
| 2067 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2068 | case SHELL_SURFACE_POPUP: |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2069 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2070 | break; |
| 2071 | } |
| 2072 | |
| 2073 | surface->type = SHELL_SURFACE_NONE; |
| 2074 | return 0; |
| 2075 | } |
| 2076 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2077 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2078 | set_surface_type(struct shell_surface *shsurf) |
| 2079 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2080 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2081 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2082 | |
| 2083 | reset_shell_surface_type(shsurf); |
| 2084 | |
| 2085 | shsurf->type = shsurf->next_type; |
| 2086 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 2087 | |
| 2088 | switch (shsurf->type) { |
| 2089 | case SHELL_SURFACE_TOPLEVEL: |
| 2090 | break; |
| 2091 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2092 | if (pev) |
| 2093 | weston_view_set_position(shsurf->view, |
| 2094 | pev->geometry.x + shsurf->transient.x, |
| 2095 | pev->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2096 | break; |
| 2097 | |
| 2098 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2099 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2100 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2101 | shsurf->saved_y = shsurf->view->geometry.y; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2102 | shsurf->saved_position_valid = true; |
| 2103 | |
| 2104 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2105 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2106 | wl_list_init(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2107 | weston_view_geometry_dirty(shsurf->view); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2108 | shsurf->saved_rotation_valid = true; |
| 2109 | } |
| 2110 | break; |
| 2111 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2112 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2113 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2114 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2115 | break; |
| 2116 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2117 | default: |
| 2118 | break; |
| 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2123 | set_toplevel(struct shell_surface *shsurf) |
| 2124 | { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2125 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2129 | shell_surface_set_toplevel(struct wl_client *client, |
| 2130 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2131 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2132 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2133 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2134 | set_toplevel(surface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | static void |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2138 | set_transient(struct shell_surface *shsurf, |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2139 | struct weston_surface *parent, int x, int y, uint32_t flags) |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2140 | { |
| 2141 | /* assign to parents output */ |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2142 | shsurf->parent = parent; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2143 | shsurf->transient.x = x; |
| 2144 | shsurf->transient.y = y; |
| 2145 | shsurf->transient.flags = flags; |
| 2146 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 2147 | } |
| 2148 | |
| 2149 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2150 | shell_surface_set_transient(struct wl_client *client, |
| 2151 | struct wl_resource *resource, |
| 2152 | struct wl_resource *parent_resource, |
| 2153 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2154 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2155 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2156 | struct weston_surface *parent = |
| 2157 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2158 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2159 | set_transient(shsurf, parent, x, y, flags); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2160 | } |
| 2161 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2162 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2163 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2164 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2165 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2169 | get_output_panel_height(struct desktop_shell *shell, |
| 2170 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2171 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2172 | struct weston_view *view; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2173 | int panel_height = 0; |
| 2174 | |
| 2175 | if (!output) |
| 2176 | return 0; |
| 2177 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2178 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2179 | if (view->surface->output == output) { |
| 2180 | panel_height = view->geometry.height; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2181 | break; |
| 2182 | } |
| 2183 | } |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2184 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2185 | return panel_height; |
| 2186 | } |
| 2187 | |
| 2188 | static void |
| 2189 | shell_surface_set_maximized(struct wl_client *client, |
| 2190 | struct wl_resource *resource, |
| 2191 | struct wl_resource *output_resource ) |
| 2192 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2193 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2194 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2195 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2196 | uint32_t edges = 0, panel_height = 0; |
| 2197 | |
| 2198 | /* get the default output, if the client set it as NULL |
| 2199 | check whether the ouput is available */ |
| 2200 | if (output_resource) |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2201 | shsurf->output = wl_resource_get_user_data(output_resource); |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 2202 | else if (es->output) |
| 2203 | shsurf->output = es->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2204 | else |
| 2205 | shsurf->output = get_default_output(es->compositor); |
| 2206 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2207 | shell = shell_surface_get_shell(shsurf); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 2208 | panel_height = get_output_panel_height(shell, shsurf->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2209 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2210 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2211 | shsurf->client->send_configure(shsurf->surface, edges, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2212 | shsurf->output->width, |
| 2213 | shsurf->output->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2214 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2215 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2216 | } |
| 2217 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2218 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2219 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height); |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2220 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2221 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2222 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2223 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2224 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2225 | { |
| 2226 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2227 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2228 | |
| 2229 | surface = weston_surface_create(ec); |
| 2230 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2231 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2232 | return NULL; |
| 2233 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2234 | view = weston_view_create(surface); |
| 2235 | if (surface == NULL) { |
| 2236 | weston_log("no memory\n"); |
| 2237 | weston_surface_destroy(surface); |
| 2238 | return NULL; |
| 2239 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2240 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2241 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2242 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2243 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2244 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2245 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2246 | pixman_region32_fini(&surface->input); |
| 2247 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2248 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2249 | weston_view_configure(view, x, y, w, h); |
| 2250 | |
| 2251 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | /* Create black surface and append it to the associated fullscreen surface. |
| 2255 | * Handle size dismatch and positioning according to the method. */ |
| 2256 | static void |
| 2257 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2258 | { |
| 2259 | struct weston_output *output = shsurf->fullscreen_output; |
| 2260 | struct weston_surface *surface = shsurf->surface; |
| 2261 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2262 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2263 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2264 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2265 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2266 | restore_output_mode(output); |
| 2267 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2268 | if (!shsurf->fullscreen.black_view) |
| 2269 | shsurf->fullscreen.black_view = |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2270 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2271 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2272 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2273 | output->width, |
| 2274 | output->height); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2275 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2276 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2277 | wl_list_insert(&shsurf->view->layer_link, |
| 2278 | &shsurf->fullscreen.black_view->layer_link); |
| 2279 | shsurf->fullscreen.black_view->surface->output = output; |
| 2280 | shsurf->fullscreen.black_view->output = output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2282 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2283 | &surf_width, &surf_height); |
| 2284 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2285 | switch (shsurf->fullscreen.type) { |
| 2286 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2287 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2288 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2289 | break; |
| 2290 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2291 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2292 | if (output->width == surf_width && |
| 2293 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2294 | weston_view_set_position(shsurf->view, |
| 2295 | output->x - surf_x, |
| 2296 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | } |
| 2299 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2300 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2301 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2302 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2303 | output_aspect = (float) output->width / |
| 2304 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2305 | /* XXX: Use surf_width and surf_height here? */ |
| 2306 | surface_aspect = (float) surface->width / |
| 2307 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2308 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2309 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2310 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2311 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2312 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2313 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2314 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2315 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2316 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2317 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2318 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2319 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2320 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2321 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2322 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2323 | break; |
| 2324 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2325 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2326 | struct weston_mode mode = {0, |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 2327 | surf_width * surface->buffer_scale, |
| 2328 | surf_height * surface->buffer_scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2329 | shsurf->fullscreen.framerate}; |
| 2330 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2331 | if (weston_output_switch_mode(output, &mode, surface->buffer_scale, |
| 2332 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2333 | weston_view_set_position(shsurf->view, |
| 2334 | output->x - surf_x, |
| 2335 | output->y - surf_y); |
| 2336 | weston_view_configure(shsurf->fullscreen.black_view, |
| 2337 | output->x - surf_x, |
| 2338 | output->y - surf_y, |
| 2339 | output->width, |
| 2340 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2341 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2342 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2343 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2344 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2345 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2346 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2347 | break; |
| 2348 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2349 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2350 | break; |
| 2351 | default: |
| 2352 | break; |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | /* make the fullscreen and black surface at the top */ |
| 2357 | static void |
| 2358 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 2359 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2360 | struct weston_output *output = shsurf->fullscreen_output; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2361 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2362 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2363 | wl_list_remove(&shsurf->view->layer_link); |
| 2364 | wl_list_insert(&shell->fullscreen_layer.view_list, |
| 2365 | &shsurf->view->layer_link); |
| 2366 | weston_surface_damage(shsurf->surface); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2367 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2368 | if (!shsurf->fullscreen.black_view) |
| 2369 | shsurf->fullscreen.black_view = |
| 2370 | create_black_surface(shsurf->surface->compositor, |
| 2371 | shsurf->surface, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2372 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2373 | output->width, |
| 2374 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2375 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2376 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2377 | wl_list_insert(&shsurf->view->layer_link, |
| 2378 | &shsurf->fullscreen.black_view->layer_link); |
| 2379 | weston_surface_damage(shsurf->fullscreen.black_view->surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | static void |
| 2383 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2384 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2385 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2386 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2387 | } |
| 2388 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2389 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2390 | set_fullscreen(struct shell_surface *shsurf, |
| 2391 | uint32_t method, |
| 2392 | uint32_t framerate, |
| 2393 | struct weston_output *output) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2394 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2395 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2396 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2397 | if (output) |
| 2398 | shsurf->output = output; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 2399 | else if (es->output) |
| 2400 | shsurf->output = es->output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2401 | else |
| 2402 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2403 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2404 | shsurf->fullscreen_output = shsurf->output; |
| 2405 | shsurf->fullscreen.type = method; |
| 2406 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2407 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2408 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2409 | shsurf->client->send_configure(shsurf->surface, 0, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2410 | shsurf->output->width, |
| 2411 | shsurf->output->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2412 | } |
| 2413 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2414 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2415 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2416 | struct wl_resource *resource, |
| 2417 | uint32_t method, |
| 2418 | uint32_t framerate, |
| 2419 | struct wl_resource *output_resource) |
| 2420 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2421 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2422 | struct weston_output *output; |
| 2423 | |
| 2424 | if (output_resource) |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2425 | output = wl_resource_get_user_data(output_resource); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2426 | else |
| 2427 | output = NULL; |
| 2428 | |
| 2429 | set_fullscreen(shsurf, method, framerate, output); |
| 2430 | } |
| 2431 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2432 | static void |
| 2433 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2434 | { |
| 2435 | /* XXX: using the same fields for transient type */ |
| 2436 | shsurf->transient.x = x; |
| 2437 | shsurf->transient.y = y; |
| 2438 | shsurf->transient.flags = flags; |
| 2439 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2440 | } |
| 2441 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2442 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2443 | |
| 2444 | static void |
| 2445 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2446 | { |
| 2447 | struct shell_seat *shseat = |
| 2448 | container_of(listener, |
| 2449 | struct shell_seat, seat_destroy_listener); |
| 2450 | struct shell_surface *shsurf, *prev = NULL; |
| 2451 | |
| 2452 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2453 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2454 | shseat->popup_grab.client = NULL; |
| 2455 | |
| 2456 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2457 | shsurf->popup.shseat = NULL; |
| 2458 | if (prev) { |
| 2459 | wl_list_init(&prev->popup.grab_link); |
| 2460 | } |
| 2461 | prev = shsurf; |
| 2462 | } |
| 2463 | wl_list_init(&prev->popup.grab_link); |
| 2464 | } |
| 2465 | |
| 2466 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2467 | free(shseat); |
| 2468 | } |
| 2469 | |
| 2470 | static struct shell_seat * |
| 2471 | create_shell_seat(struct weston_seat *seat) |
| 2472 | { |
| 2473 | struct shell_seat *shseat; |
| 2474 | |
| 2475 | shseat = calloc(1, sizeof *shseat); |
| 2476 | if (!shseat) { |
| 2477 | weston_log("no memory to allocate shell seat\n"); |
| 2478 | return NULL; |
| 2479 | } |
| 2480 | |
| 2481 | shseat->seat = seat; |
| 2482 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2483 | |
| 2484 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2485 | wl_signal_add(&seat->destroy_signal, |
| 2486 | &shseat->seat_destroy_listener); |
| 2487 | |
| 2488 | return shseat; |
| 2489 | } |
| 2490 | |
| 2491 | static struct shell_seat * |
| 2492 | get_shell_seat(struct weston_seat *seat) |
| 2493 | { |
| 2494 | struct wl_listener *listener; |
| 2495 | |
| 2496 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2497 | if (listener == NULL) |
| 2498 | return create_shell_seat(seat); |
| 2499 | |
| 2500 | return container_of(listener, |
| 2501 | struct shell_seat, seat_destroy_listener); |
| 2502 | } |
| 2503 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2504 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2505 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2506 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2507 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2508 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2509 | struct shell_seat *shseat = |
| 2510 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2511 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2512 | wl_fixed_t sx, sy; |
| 2513 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2514 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2515 | pointer->x, pointer->y, |
| 2516 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2517 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2518 | if (view && view->surface->resource && |
| 2519 | wl_resource_get_client(view->surface->resource) == client) { |
| 2520 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2521 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2522 | weston_pointer_set_focus(pointer, NULL, |
| 2523 | wl_fixed_from_int(0), |
| 2524 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2529 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2530 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2531 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2532 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2533 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2534 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2535 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2536 | weston_pointer_move(pointer, x, y); |
| 2537 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2538 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2539 | weston_view_from_global_fixed(pointer->focus, |
| 2540 | pointer->x, pointer->y, |
| 2541 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2542 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2543 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2547 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2548 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2549 | { |
| 2550 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2551 | struct shell_seat *shseat = |
| 2552 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2553 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2554 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2555 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2556 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2557 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2558 | resource_list = &grab->pointer->focus_resource_list; |
| 2559 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2560 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2561 | wl_resource_for_each(resource, resource_list) { |
| 2562 | wl_pointer_send_button(resource, serial, |
| 2563 | time, button, state); |
| 2564 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2565 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2566 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2567 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2568 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2569 | } |
| 2570 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2571 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2572 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2573 | } |
| 2574 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2575 | static void |
| 2576 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2577 | { |
| 2578 | popup_grab_end(grab->pointer); |
| 2579 | } |
| 2580 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2581 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2582 | popup_grab_focus, |
| 2583 | popup_grab_motion, |
| 2584 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2585 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2586 | }; |
| 2587 | |
| 2588 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2589 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2590 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2591 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2592 | struct shell_seat *shseat = |
| 2593 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2594 | struct shell_surface *shsurf; |
| 2595 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2596 | |
| 2597 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2598 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2599 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2600 | shseat->popup_grab.grab.interface = NULL; |
| 2601 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2602 | /* Send the popup_done event to all the popups open */ |
| 2603 | 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] | 2604 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2605 | shsurf->popup.shseat = NULL; |
| 2606 | if (prev) { |
| 2607 | wl_list_init(&prev->popup.grab_link); |
| 2608 | } |
| 2609 | prev = shsurf; |
| 2610 | } |
| 2611 | wl_list_init(&prev->popup.grab_link); |
| 2612 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | static void |
| 2617 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2618 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2619 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2620 | |
| 2621 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2622 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2623 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2624 | /* We must make sure here that this popup was opened after |
| 2625 | * a mouse press, and not just by moving around with other |
| 2626 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2627 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2628 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2629 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2630 | 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] | 2631 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2632 | } else { |
| 2633 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2634 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | static void |
| 2638 | remove_popup_grab(struct shell_surface *shsurf) |
| 2639 | { |
| 2640 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2641 | |
| 2642 | wl_list_remove(&shsurf->popup.grab_link); |
| 2643 | wl_list_init(&shsurf->popup.grab_link); |
| 2644 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2645 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2646 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2647 | } |
| 2648 | } |
| 2649 | |
| 2650 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2651 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2652 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2653 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2654 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2655 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2656 | shsurf->surface->output = parent_view->output; |
| 2657 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2658 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2659 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2660 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2661 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2662 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2663 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2664 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2665 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2666 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2667 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2668 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | static void |
| 2672 | shell_surface_set_popup(struct wl_client *client, |
| 2673 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2674 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2675 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2676 | struct wl_resource *parent_resource, |
| 2677 | int32_t x, int32_t y, uint32_t flags) |
| 2678 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2679 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2680 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2681 | shsurf->type = SHELL_SURFACE_POPUP; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2682 | shsurf->parent = wl_resource_get_user_data(parent_resource); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2683 | shsurf->popup.shseat = get_shell_seat(wl_resource_get_user_data(seat_resource)); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2684 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2685 | shsurf->popup.x = x; |
| 2686 | shsurf->popup.y = y; |
| 2687 | } |
| 2688 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2689 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2690 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2691 | shell_surface_move, |
| 2692 | shell_surface_resize, |
| 2693 | shell_surface_set_toplevel, |
| 2694 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2695 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2696 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2697 | shell_surface_set_maximized, |
| 2698 | shell_surface_set_title, |
| 2699 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2700 | }; |
| 2701 | |
| 2702 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2703 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2704 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2705 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2706 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2707 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2708 | remove_popup_grab(shsurf); |
| 2709 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2710 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2711 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2712 | shell_surface_is_top_fullscreen(shsurf)) |
| 2713 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2714 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2715 | if (shsurf->fullscreen.black_view) |
| 2716 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2717 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2718 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2719 | * we can always remove the listener. |
| 2720 | */ |
| 2721 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2722 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2723 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2724 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2725 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2726 | weston_view_destroy(shsurf->view); |
| 2727 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2728 | wl_list_remove(&shsurf->link); |
| 2729 | free(shsurf); |
| 2730 | } |
| 2731 | |
| 2732 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2733 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2734 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2735 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2736 | |
| 2737 | destroy_shell_surface(shsurf); |
| 2738 | } |
| 2739 | |
| 2740 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2741 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2742 | { |
| 2743 | struct shell_surface *shsurf = container_of(listener, |
| 2744 | struct shell_surface, |
| 2745 | surface_destroy_listener); |
| 2746 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2747 | if (shsurf->resource) |
| 2748 | wl_resource_destroy(shsurf->resource); |
| 2749 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2750 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2751 | } |
| 2752 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2753 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2754 | shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2755 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2756 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2757 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2758 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2759 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2760 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2761 | else |
| 2762 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2763 | } |
| 2764 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2765 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2766 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2767 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2768 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2769 | struct shell_surface *shsurf; |
| 2770 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2771 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2772 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2773 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2774 | } |
| 2775 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2776 | shsurf = calloc(1, sizeof *shsurf); |
| 2777 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2778 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2779 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2780 | } |
| 2781 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2782 | shsurf->view = weston_view_create(surface); |
| 2783 | if (!shsurf->view) { |
| 2784 | weston_log("no memory to allocate shell surface\n"); |
| 2785 | free(shsurf); |
| 2786 | return NULL; |
| 2787 | } |
| 2788 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2789 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2790 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2791 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2792 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2793 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2794 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2795 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2796 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2797 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2798 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2799 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2800 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2801 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2802 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2803 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2804 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2805 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2806 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2807 | |
| 2808 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2809 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2810 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2811 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2812 | /* empty when not in use */ |
| 2813 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2814 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2815 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2816 | wl_list_init(&shsurf->workspace_transform.link); |
| 2817 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2818 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2819 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2820 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2821 | shsurf->client = client; |
| 2822 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2823 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2824 | } |
| 2825 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2826 | static struct weston_view * |
| 2827 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2828 | { |
| 2829 | return shsurf->view; |
| 2830 | } |
| 2831 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2832 | static void |
| 2833 | shell_get_shell_surface(struct wl_client *client, |
| 2834 | struct wl_resource *resource, |
| 2835 | uint32_t id, |
| 2836 | struct wl_resource *surface_resource) |
| 2837 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2838 | struct weston_surface *surface = |
| 2839 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2840 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2841 | struct shell_surface *shsurf; |
| 2842 | |
| 2843 | if (get_shell_surface(surface)) { |
| 2844 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2845 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2846 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2847 | return; |
| 2848 | } |
| 2849 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2850 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2851 | if (!shsurf) { |
| 2852 | wl_resource_post_error(surface_resource, |
| 2853 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2854 | "surface->configure already set"); |
| 2855 | return; |
| 2856 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2857 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2858 | shsurf->resource = |
| 2859 | wl_resource_create(client, |
| 2860 | &wl_shell_surface_interface, 1, id); |
| 2861 | wl_resource_set_implementation(shsurf->resource, |
| 2862 | &shell_surface_implementation, |
| 2863 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 2867 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2868 | }; |
| 2869 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2870 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 2871 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 2872 | |
| 2873 | static int |
| 2874 | screensaver_timeout(void *data) |
| 2875 | { |
| 2876 | struct desktop_shell *shell = data; |
| 2877 | |
| 2878 | shell_fade(shell, FADE_OUT); |
| 2879 | |
| 2880 | return 1; |
| 2881 | } |
| 2882 | |
| 2883 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2884 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2885 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2886 | struct desktop_shell *shell = |
| 2887 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2888 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2889 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2890 | |
| 2891 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 2892 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2896 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2897 | { |
| 2898 | if (shell->screensaver.binding) |
| 2899 | return; |
| 2900 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2901 | if (!shell->screensaver.path) { |
| 2902 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2903 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2904 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2905 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2906 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2907 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2908 | return; |
| 2909 | } |
| 2910 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2911 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2912 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2913 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2914 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2918 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2919 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2920 | if (shell->screensaver.process.pid == 0) |
| 2921 | return; |
| 2922 | |
| 2923 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2927 | configure_static_view(struct weston_view *ev, struct weston_layer *layer, int32_t width, int32_t height) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2928 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2929 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2930 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2931 | if (width == 0) |
| 2932 | return; |
| 2933 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2934 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 2935 | if (v->output == ev->output && v != ev) { |
| 2936 | weston_view_unmap(v); |
| 2937 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2938 | } |
| 2939 | } |
| 2940 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2941 | weston_view_configure(ev, ev->output->x, ev->output->y, width, height); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2942 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2943 | if (wl_list_empty(&ev->layer_link)) { |
| 2944 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 2945 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2950 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2951 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2952 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2953 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2954 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2955 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2956 | |
| 2957 | configure_static_view(view, &shell->background_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2961 | desktop_shell_set_background(struct wl_client *client, |
| 2962 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2963 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2964 | struct wl_resource *surface_resource) |
| 2965 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2966 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2967 | struct weston_surface *surface = |
| 2968 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2969 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2970 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2971 | if (surface->configure) { |
| 2972 | wl_resource_post_error(surface_resource, |
| 2973 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2974 | "surface role already assigned"); |
| 2975 | return; |
| 2976 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2977 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2978 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 2979 | weston_view_destroy(view); |
| 2980 | view = weston_view_create(surface); |
| 2981 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2982 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2983 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2984 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2985 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2986 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2987 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2988 | surface->output->width, |
| 2989 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2993 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2994 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2995 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2996 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2997 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2998 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2999 | |
| 3000 | configure_static_view(view, &shell->panel_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3004 | desktop_shell_set_panel(struct wl_client *client, |
| 3005 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3006 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3007 | struct wl_resource *surface_resource) |
| 3008 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3009 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3010 | struct weston_surface *surface = |
| 3011 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3012 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3013 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3014 | if (surface->configure) { |
| 3015 | wl_resource_post_error(surface_resource, |
| 3016 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3017 | "surface role already assigned"); |
| 3018 | return; |
| 3019 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3020 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3021 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3022 | weston_view_destroy(view); |
| 3023 | view = weston_view_create(surface); |
| 3024 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3025 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3026 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3027 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3028 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3029 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3030 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3031 | surface->output->width, |
| 3032 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3033 | } |
| 3034 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3035 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3036 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3037 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3038 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3039 | struct weston_view *view; |
| 3040 | |
| 3041 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3042 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3043 | if (width == 0) |
| 3044 | return; |
| 3045 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3046 | surface->width = width; |
| 3047 | surface->height = height; |
| 3048 | view->geometry.width = width; |
| 3049 | view->geometry.height = height; |
| 3050 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3051 | |
| 3052 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3053 | wl_list_insert(&shell->lock_layer.view_list, |
| 3054 | &view->layer_link); |
| 3055 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3056 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3061 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3062 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3063 | struct desktop_shell *shell = |
| 3064 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3065 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3066 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3067 | shell->lock_surface = NULL; |
| 3068 | } |
| 3069 | |
| 3070 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3071 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3072 | struct wl_resource *resource, |
| 3073 | struct wl_resource *surface_resource) |
| 3074 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3075 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3076 | struct weston_surface *surface = |
| 3077 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3078 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3079 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3080 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3081 | if (!shell->locked) |
| 3082 | return; |
| 3083 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3084 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3085 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3086 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3087 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3088 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3089 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3090 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3091 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3092 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3096 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3097 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3098 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3099 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3100 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3101 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3102 | wl_list_remove(&shell->lock_layer.link); |
| 3103 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3104 | &shell->fullscreen_layer.link); |
| 3105 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3106 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3107 | if (shell->showing_input_panels) { |
| 3108 | wl_list_insert(&shell->panel_layer.link, |
| 3109 | &shell->input_panel_layer.link); |
| 3110 | wl_list_insert(&shell->input_panel_layer.link, |
| 3111 | &ws->layer.link); |
| 3112 | } else { |
| 3113 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3114 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3115 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3116 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3117 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3118 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3119 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3120 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | static void |
| 3124 | desktop_shell_unlock(struct wl_client *client, |
| 3125 | struct wl_resource *resource) |
| 3126 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3127 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3128 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3129 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3130 | |
| 3131 | if (shell->locked) |
| 3132 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3133 | } |
| 3134 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3135 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3136 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3137 | struct wl_resource *resource, |
| 3138 | struct wl_resource *surface_resource) |
| 3139 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3140 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3141 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3142 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3143 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3144 | } |
| 3145 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3146 | static void |
| 3147 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3148 | struct wl_resource *resource) |
| 3149 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3150 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3151 | |
| 3152 | shell_fade_startup(shell); |
| 3153 | } |
| 3154 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3155 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3156 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3157 | desktop_shell_set_panel, |
| 3158 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3159 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3160 | desktop_shell_set_grab_surface, |
| 3161 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3162 | }; |
| 3163 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3164 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3165 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3166 | { |
| 3167 | struct shell_surface *shsurf; |
| 3168 | |
| 3169 | shsurf = get_shell_surface(surface); |
| 3170 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3171 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3172 | return shsurf->type; |
| 3173 | } |
| 3174 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3175 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3176 | 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] | 3177 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3178 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3179 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3180 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3181 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3182 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3183 | if (surface == NULL) |
| 3184 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3185 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3186 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3187 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3188 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3189 | return; |
| 3190 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3191 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3195 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3196 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3197 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3198 | struct weston_surface *surface; |
| 3199 | struct shell_surface *shsurf; |
| 3200 | |
| 3201 | surface = weston_surface_get_main_surface(focus); |
| 3202 | if (surface == NULL) |
| 3203 | return; |
| 3204 | |
| 3205 | shsurf = get_shell_surface(surface); |
| 3206 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3207 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
| 3208 | return; |
| 3209 | |
| 3210 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3211 | } |
| 3212 | |
| 3213 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3214 | 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] | 3215 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3216 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3217 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3218 | uint32_t edges = 0; |
| 3219 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3220 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3221 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3222 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3223 | if (surface == NULL) |
| 3224 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3225 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3226 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3227 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3228 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3229 | return; |
| 3230 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3231 | weston_view_from_global(shsurf->view, |
| 3232 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3233 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3234 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3235 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3236 | if (x < shsurf->view->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3237 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3238 | else if (x < 2 * shsurf->view->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3239 | edges |= 0; |
| 3240 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3241 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3242 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3243 | if (y < shsurf->view->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3244 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3245 | else if (y < 2 * shsurf->view->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3246 | edges |= 0; |
| 3247 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3248 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3249 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3250 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3254 | 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] | 3255 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3256 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3257 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3258 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3259 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3260 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3261 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3262 | /* XXX: broken for windows containing sub-surfaces */ |
| 3263 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3264 | if (surface == NULL) |
| 3265 | return; |
| 3266 | |
| 3267 | shsurf = get_shell_surface(surface); |
| 3268 | if (!shsurf) |
| 3269 | return; |
| 3270 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3271 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3272 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3273 | if (shsurf->view->alpha > 1.0) |
| 3274 | shsurf->view->alpha = 1.0; |
| 3275 | if (shsurf->view->alpha < step) |
| 3276 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3277 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3278 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3279 | weston_surface_damage(surface); |
| 3280 | } |
| 3281 | |
| 3282 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3283 | 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] | 3284 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3285 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3286 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3287 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3288 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3289 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3290 | |
| 3291 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3292 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3293 | wl_fixed_to_double(seat->pointer->x), |
| 3294 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3295 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3296 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3297 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3298 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3299 | increment = -output->zoom.increment; |
| 3300 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3301 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3302 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3303 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3304 | else |
| 3305 | increment = 0; |
| 3306 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3307 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3308 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3309 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3310 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3311 | else if (output->zoom.level > output->zoom.max_level) |
| 3312 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3313 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3314 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3315 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3316 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3317 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3318 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3319 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3320 | } |
| 3321 | } |
| 3322 | } |
| 3323 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3324 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3325 | 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] | 3326 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3327 | { |
| 3328 | do_zoom(seat, time, 0, axis, value); |
| 3329 | } |
| 3330 | |
| 3331 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3332 | 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] | 3333 | void *data) |
| 3334 | { |
| 3335 | do_zoom(seat, time, key, 0, 0); |
| 3336 | } |
| 3337 | |
| 3338 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3339 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3340 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3341 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3342 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3343 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3344 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 3348 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 3349 | |
| 3350 | struct alt_tab { |
| 3351 | struct desktop_shell *shell; |
| 3352 | struct weston_keyboard_grab grab; |
| 3353 | |
| 3354 | struct wl_list *current; |
| 3355 | |
| 3356 | struct wl_list preview_list; |
| 3357 | }; |
| 3358 | |
| 3359 | struct alt_tab_preview { |
| 3360 | struct alt_tab *alt_tab; |
| 3361 | |
| 3362 | struct weston_view *view; |
| 3363 | struct weston_transform transform; |
| 3364 | |
| 3365 | struct wl_listener listener; |
| 3366 | |
| 3367 | struct wl_list link; |
| 3368 | }; |
| 3369 | |
| 3370 | static void |
| 3371 | alt_tab_next(struct alt_tab *alt_tab) |
| 3372 | { |
| 3373 | alt_tab->current = alt_tab->current->next; |
| 3374 | |
| 3375 | /* Make sure we're not pointing to the list header e.g. after |
| 3376 | * cycling through the whole list. */ |
| 3377 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 3378 | alt_tab->current = alt_tab->current->next; |
| 3379 | } |
| 3380 | |
| 3381 | static void |
| 3382 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 3383 | { |
| 3384 | struct alt_tab_preview *preview, *next; |
| 3385 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 3386 | |
| 3387 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 3388 | preview = wl_container_of(alt_tab->current, preview, link); |
| 3389 | |
| 3390 | activate(alt_tab->shell, preview->view->surface, |
| 3391 | (struct weston_seat *) keyboard->seat); |
| 3392 | } |
| 3393 | |
| 3394 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 3395 | wl_list_remove(&preview->link); |
| 3396 | wl_list_remove(&preview->listener.link); |
| 3397 | weston_view_destroy(preview->view); |
| 3398 | free(preview); |
| 3399 | } |
| 3400 | |
| 3401 | weston_keyboard_end_grab(keyboard); |
| 3402 | if (keyboard->input_method_resource) |
| 3403 | keyboard->grab = &keyboard->input_method_grab; |
| 3404 | |
| 3405 | free(alt_tab); |
| 3406 | } |
| 3407 | |
| 3408 | static void |
| 3409 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3410 | { |
| 3411 | struct alt_tab_preview *preview = |
| 3412 | container_of(listener, struct alt_tab_preview, listener); |
| 3413 | struct alt_tab *alt_tab = preview->alt_tab; |
| 3414 | int advance = 0; |
| 3415 | |
| 3416 | /* If the preview that we're removing is the currently selected one, |
| 3417 | * we want to move to the next one. So we move to ->prev and then |
| 3418 | * call _next() after removing the preview. */ |
| 3419 | if (alt_tab->current == &preview->link) { |
| 3420 | alt_tab->current = alt_tab->current->prev; |
| 3421 | advance = 1; |
| 3422 | } |
| 3423 | |
| 3424 | wl_list_remove(&preview->listener.link); |
| 3425 | wl_list_remove(&preview->link); |
| 3426 | |
| 3427 | free(preview); |
| 3428 | |
| 3429 | if (advance) |
| 3430 | alt_tab_next(alt_tab); |
| 3431 | |
| 3432 | /* If the last preview goes away, stop the alt-tab */ |
| 3433 | if (wl_list_empty(alt_tab->current)) |
| 3434 | alt_tab_destroy(alt_tab); |
| 3435 | } |
| 3436 | |
| 3437 | static void |
| 3438 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 3439 | uint32_t time, uint32_t key, uint32_t state_w) |
| 3440 | { |
| 3441 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3442 | enum wl_keyboard_key_state state = state_w; |
| 3443 | |
| 3444 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 3445 | alt_tab_next(alt_tab); |
| 3446 | } |
| 3447 | |
| 3448 | static void |
| 3449 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 3450 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3451 | uint32_t mods_locked, uint32_t group) |
| 3452 | { |
| 3453 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3454 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 3455 | |
| 3456 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 3457 | alt_tab_destroy(alt_tab); |
| 3458 | } |
| 3459 | |
| 3460 | static void |
| 3461 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 3462 | { |
| 3463 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 3464 | |
| 3465 | alt_tab_destroy(alt_tab); |
| 3466 | } |
| 3467 | |
| 3468 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 3469 | alt_tab_key, |
| 3470 | alt_tab_modifier, |
| 3471 | alt_tab_cancel, |
| 3472 | }; |
| 3473 | |
| 3474 | static int |
| 3475 | view_for_alt_tab(struct weston_view *view) |
| 3476 | { |
| 3477 | if (!get_shell_surface(view->surface)) |
| 3478 | return 0; |
| 3479 | |
| 3480 | if (get_shell_surface_type(view->surface) == SHELL_SURFACE_TRANSIENT) |
| 3481 | return 0; |
| 3482 | |
| 3483 | if (view != get_default_view(view->surface)) |
| 3484 | return 0; |
| 3485 | |
| 3486 | return 1; |
| 3487 | } |
| 3488 | |
| 3489 | static void |
| 3490 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 3491 | void *data) |
| 3492 | { |
| 3493 | struct alt_tab *alt_tab; |
| 3494 | struct desktop_shell *shell = data; |
| 3495 | struct weston_output *output = get_default_output(shell->compositor); |
| 3496 | struct workspace *ws; |
| 3497 | struct weston_view *view; |
| 3498 | int num_surfaces = 0; |
| 3499 | int x, y, side, margin; |
| 3500 | |
| 3501 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3502 | |
| 3503 | if (view_for_alt_tab(view)) |
| 3504 | num_surfaces++; |
| 3505 | } |
| 3506 | |
| 3507 | if (!num_surfaces) |
| 3508 | return; |
| 3509 | |
| 3510 | alt_tab = malloc(sizeof *alt_tab); |
| 3511 | if (!alt_tab) |
| 3512 | return; |
| 3513 | |
| 3514 | alt_tab->shell = shell; |
| 3515 | wl_list_init(&alt_tab->preview_list); |
| 3516 | alt_tab->current = &alt_tab->preview_list; |
| 3517 | |
| 3518 | restore_all_output_modes(shell->compositor); |
| 3519 | lower_fullscreen_layer(alt_tab->shell); |
| 3520 | |
| 3521 | alt_tab->grab.interface = &alt_tab_grab; |
| 3522 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 3523 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 3524 | |
| 3525 | ws = get_current_workspace(shell); |
| 3526 | |
| 3527 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 3528 | * and/or add a black surrounding background à la gnome-shell */ |
| 3529 | |
| 3530 | /* Determine the size for each preview */ |
| 3531 | side = output->width / num_surfaces; |
| 3532 | if (side > 200) |
| 3533 | side = 200; |
| 3534 | margin = side / 4; |
| 3535 | side -= margin; |
| 3536 | |
| 3537 | x = margin; |
| 3538 | y = (output->height - side) / 2; |
| 3539 | |
| 3540 | /* Create a view for each surface */ |
| 3541 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 3542 | struct alt_tab_preview *preview; |
| 3543 | struct weston_view *v; |
| 3544 | float scale; |
| 3545 | |
| 3546 | if (!view_for_alt_tab(view)) |
| 3547 | continue; |
| 3548 | |
| 3549 | preview = malloc(sizeof *preview); |
| 3550 | if (!preview) { |
| 3551 | alt_tab_destroy(alt_tab); |
| 3552 | return; |
| 3553 | } |
| 3554 | |
| 3555 | preview->alt_tab = alt_tab; |
| 3556 | |
| 3557 | preview->view = v = weston_view_create(view->surface); |
| 3558 | v->output = view->output; |
| 3559 | weston_view_restack(v, &ws->layer.view_list); |
| 3560 | weston_view_configure(v, x, y, view->geometry.width, view->geometry.height); |
| 3561 | |
| 3562 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 3563 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 3564 | |
| 3565 | if (view->geometry.width > view->geometry.height) |
| 3566 | scale = side / (float) view->geometry.width; |
| 3567 | else |
| 3568 | scale = side / (float) view->geometry.height; |
| 3569 | |
| 3570 | wl_list_insert(&v->geometry.transformation_list, |
| 3571 | &preview->transform.link); |
| 3572 | weston_matrix_init(&preview->transform.matrix); |
| 3573 | weston_matrix_scale(&preview->transform.matrix, |
| 3574 | scale, scale, 1.0f); |
| 3575 | |
| 3576 | weston_view_geometry_dirty(v); |
| 3577 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 3578 | |
| 3579 | /* Insert at the end of the list */ |
| 3580 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 3581 | |
| 3582 | x += side + margin; |
| 3583 | } |
| 3584 | |
| 3585 | /* Start at the second preview so a simple <alt>tab changes window. |
| 3586 | * We set `current' to the first preview and not the second because |
| 3587 | * we're going to receive a key press callback for the initial |
| 3588 | * <alt>tab which will make `current' point to the second element. */ |
| 3589 | alt_tab_next(alt_tab); |
| 3590 | } |
| 3591 | |
| 3592 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3593 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3594 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3595 | { |
| 3596 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3597 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3598 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3599 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3600 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3601 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3602 | weston_pointer_move(pointer, x, y); |
| 3603 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3604 | if (!shsurf) |
| 3605 | return; |
| 3606 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3607 | cx = 0.5f * shsurf->view->geometry.width; |
| 3608 | cy = 0.5f * shsurf->view->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3609 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3610 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3611 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3612 | r = sqrtf(dx * dx + dy * dy); |
| 3613 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3614 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3615 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3616 | |
| 3617 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3618 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3619 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3620 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3621 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3622 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3623 | |
| 3624 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3625 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3626 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3627 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3628 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3629 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3630 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3631 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3632 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3633 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3634 | wl_list_init(&shsurf->rotation.transform.link); |
| 3635 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3636 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3637 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3638 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3639 | /* We need to adjust the position of the surface |
| 3640 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3641 | cposx = shsurf->view->geometry.x + cx; |
| 3642 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3643 | dposx = rotate->center.x - cposx; |
| 3644 | dposy = rotate->center.y - cposy; |
| 3645 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3646 | weston_view_set_position(shsurf->view, |
| 3647 | shsurf->view->geometry.x + dposx, |
| 3648 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3649 | } |
| 3650 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3651 | /* Repaint implies weston_surface_update_transform(), which |
| 3652 | * lazily applies the damage due to rotation update. |
| 3653 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3654 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3658 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3659 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3660 | { |
| 3661 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3662 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3663 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3664 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3665 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3666 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3667 | if (pointer->button_count == 0 && |
| 3668 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3669 | if (shsurf) |
| 3670 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3671 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3672 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3673 | free(rotate); |
| 3674 | } |
| 3675 | } |
| 3676 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3677 | static void |
| 3678 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3679 | { |
| 3680 | struct rotate_grab *rotate = |
| 3681 | container_of(grab, struct rotate_grab, base.grab); |
| 3682 | |
| 3683 | shell_grab_end(&rotate->base); |
| 3684 | free(rotate); |
| 3685 | } |
| 3686 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3687 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3688 | noop_grab_focus, |
| 3689 | rotate_grab_motion, |
| 3690 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3691 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3692 | }; |
| 3693 | |
| 3694 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3695 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3696 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3697 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3698 | float dx, dy; |
| 3699 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3700 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3701 | rotate = malloc(sizeof *rotate); |
| 3702 | if (!rotate) |
| 3703 | return; |
| 3704 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3705 | weston_view_to_global_float(surface->view, |
| 3706 | surface->view->geometry.width * 0.5f, |
| 3707 | surface->view->geometry.height * 0.5f, |
| 3708 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3709 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3710 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3711 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3712 | r = sqrtf(dx * dx + dy * dy); |
| 3713 | if (r > 20.0f) { |
| 3714 | struct weston_matrix inverse; |
| 3715 | |
| 3716 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3717 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3718 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3719 | |
| 3720 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3721 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3722 | } else { |
| 3723 | weston_matrix_init(&surface->rotation.rotation); |
| 3724 | weston_matrix_init(&rotate->rotation); |
| 3725 | } |
| 3726 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3727 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3728 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3732 | 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] | 3733 | void *data) |
| 3734 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3735 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3736 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3737 | struct shell_surface *surface; |
| 3738 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3739 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3740 | if (base_surface == NULL) |
| 3741 | return; |
| 3742 | |
| 3743 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3744 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 3745 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3746 | return; |
| 3747 | |
| 3748 | surface_rotate(surface, seat); |
| 3749 | } |
| 3750 | |
| 3751 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3752 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 3753 | { |
| 3754 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3755 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3756 | |
| 3757 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3758 | wl_list_for_each_reverse_safe(view, prev, |
| 3759 | &shell->fullscreen_layer.view_list, |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3760 | layer_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3761 | weston_view_restack(view, &ws->layer.view_list); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3765 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3766 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3767 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3768 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3769 | struct weston_view *main_view; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3770 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3771 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3772 | struct weston_surface *old_es; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3773 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3774 | main_surface = weston_surface_get_main_surface(es); |
| 3775 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3776 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3777 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3778 | state = ensure_focus_state(shell, seat); |
| 3779 | if (state == NULL) |
| 3780 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3781 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3782 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3783 | state->keyboard_focus = es; |
| 3784 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3785 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3786 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3787 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3788 | case SHELL_SURFACE_FULLSCREEN: |
| 3789 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3790 | shell_stack_fullscreen(get_shell_surface(main_surface)); |
| 3791 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3792 | return; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3793 | default: |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3794 | restore_all_output_modes(shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3795 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3796 | main_view = get_default_view(main_surface); |
| 3797 | if (main_view) |
| 3798 | weston_view_restack(main_view, &ws->layer.view_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3799 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3800 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3801 | |
| 3802 | if (shell->focus_animation_type != ANIMATION_NONE) |
| 3803 | animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3804 | } |
| 3805 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3806 | /* no-op func for checking black surface */ |
| 3807 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3808 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3809 | { |
| 3810 | } |
| 3811 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3812 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3813 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 3814 | { |
| 3815 | if (es->configure == black_surface_configure) { |
| 3816 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3817 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3818 | return true; |
| 3819 | } |
| 3820 | return false; |
| 3821 | } |
| 3822 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3823 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3824 | activate_binding(struct weston_seat *seat, |
| 3825 | struct desktop_shell *shell, |
| 3826 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3827 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3828 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3829 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3830 | if (!focus) |
| 3831 | return; |
| 3832 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3833 | if (is_black_surface(focus, &main_surface)) |
| 3834 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3835 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3836 | main_surface = weston_surface_get_main_surface(focus); |
| 3837 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3838 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3839 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3840 | activate(shell, focus, seat); |
| 3841 | } |
| 3842 | |
| 3843 | static void |
| 3844 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 3845 | void *data) |
| 3846 | { |
| 3847 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 3848 | return; |
| 3849 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3850 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | static void |
| 3854 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3855 | { |
| 3856 | if (seat->touch->grab != &seat->touch->default_grab) |
| 3857 | return; |
| 3858 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3859 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3863 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3864 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3865 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3866 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3867 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3868 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3869 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3870 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3871 | |
| 3872 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3873 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3874 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3875 | * toplevel layers. This way nothing else can show or receive |
| 3876 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3877 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3878 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3879 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3880 | if (shell->showing_input_panels) |
| 3881 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3882 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3883 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3884 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3885 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3886 | launch_screensaver(shell); |
| 3887 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3888 | /* TODO: disable bindings that should not work while locked. */ |
| 3889 | |
| 3890 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3894 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3895 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3896 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3897 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3898 | return; |
| 3899 | } |
| 3900 | |
| 3901 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3902 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3903 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3904 | return; |
| 3905 | } |
| 3906 | |
| 3907 | if (shell->prepare_event_sent) |
| 3908 | return; |
| 3909 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3910 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3911 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3915 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3916 | { |
| 3917 | struct desktop_shell *shell = data; |
| 3918 | |
| 3919 | shell->fade.animation = NULL; |
| 3920 | |
| 3921 | switch (shell->fade.type) { |
| 3922 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3923 | weston_surface_destroy(shell->fade.view->surface); |
| 3924 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3925 | break; |
| 3926 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3927 | lock(shell); |
| 3928 | break; |
| 3929 | } |
| 3930 | } |
| 3931 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3932 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3933 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3934 | { |
| 3935 | struct weston_compositor *compositor = shell->compositor; |
| 3936 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3937 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3938 | |
| 3939 | surface = weston_surface_create(compositor); |
| 3940 | if (!surface) |
| 3941 | return NULL; |
| 3942 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3943 | view = weston_view_create(surface); |
| 3944 | if (!view) { |
| 3945 | weston_surface_destroy(surface); |
| 3946 | return NULL; |
| 3947 | } |
| 3948 | |
| 3949 | weston_view_configure(view, 0, 0, 8192, 8192); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3950 | 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] | 3951 | wl_list_insert(&compositor->fade_layer.view_list, |
| 3952 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3953 | pixman_region32_init(&surface->input); |
| 3954 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3955 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | static void |
| 3959 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 3960 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3961 | float tint; |
| 3962 | |
| 3963 | switch (type) { |
| 3964 | case FADE_IN: |
| 3965 | tint = 0.0; |
| 3966 | break; |
| 3967 | case FADE_OUT: |
| 3968 | tint = 1.0; |
| 3969 | break; |
| 3970 | default: |
| 3971 | weston_log("shell: invalid fade type\n"); |
| 3972 | return; |
| 3973 | } |
| 3974 | |
| 3975 | shell->fade.type = type; |
| 3976 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3977 | if (shell->fade.view == NULL) { |
| 3978 | shell->fade.view = shell_fade_create_surface(shell); |
| 3979 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3980 | return; |
| 3981 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3982 | shell->fade.view->alpha = 1.0 - tint; |
| 3983 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3984 | } |
| 3985 | |
| 3986 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 3987 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3988 | else |
| 3989 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3990 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 3991 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3992 | shell_fade_done, shell); |
| 3993 | } |
| 3994 | |
| 3995 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3996 | do_shell_fade_startup(void *data) |
| 3997 | { |
| 3998 | struct desktop_shell *shell = data; |
| 3999 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4000 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4001 | shell_fade(shell, FADE_IN); |
| 4002 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4003 | weston_surface_destroy(shell->fade.view->surface); |
| 4004 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4005 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | static void |
| 4009 | shell_fade_startup(struct desktop_shell *shell) |
| 4010 | { |
| 4011 | struct wl_event_loop *loop; |
| 4012 | |
| 4013 | if (!shell->fade.startup_timer) |
| 4014 | return; |
| 4015 | |
| 4016 | wl_event_source_remove(shell->fade.startup_timer); |
| 4017 | shell->fade.startup_timer = NULL; |
| 4018 | |
| 4019 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4020 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4021 | } |
| 4022 | |
| 4023 | static int |
| 4024 | fade_startup_timeout(void *data) |
| 4025 | { |
| 4026 | struct desktop_shell *shell = data; |
| 4027 | |
| 4028 | shell_fade_startup(shell); |
| 4029 | return 0; |
| 4030 | } |
| 4031 | |
| 4032 | static void |
| 4033 | shell_fade_init(struct desktop_shell *shell) |
| 4034 | { |
| 4035 | /* Make compositor output all black, and wait for the desktop-shell |
| 4036 | * client to signal it is ready, then fade in. The timer triggers a |
| 4037 | * fade-in, in case the desktop-shell client takes too long. |
| 4038 | */ |
| 4039 | |
| 4040 | struct wl_event_loop *loop; |
| 4041 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4042 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4043 | weston_log("%s: warning: fade surface already exists\n", |
| 4044 | __func__); |
| 4045 | return; |
| 4046 | } |
| 4047 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4048 | shell->fade.view = shell_fade_create_surface(shell); |
| 4049 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4050 | return; |
| 4051 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4052 | weston_view_update_transform(shell->fade.view); |
| 4053 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4054 | |
| 4055 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4056 | shell->fade.startup_timer = |
| 4057 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4058 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4059 | } |
| 4060 | |
| 4061 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4062 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4063 | { |
| 4064 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4065 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4066 | |
| 4067 | shell_fade(shell, FADE_OUT); |
| 4068 | /* lock() is called from shell_fade_done() */ |
| 4069 | } |
| 4070 | |
| 4071 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4072 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4073 | { |
| 4074 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4075 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4076 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4077 | unlock(shell); |
| 4078 | } |
| 4079 | |
| 4080 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4081 | show_input_panels(struct wl_listener *listener, void *data) |
| 4082 | { |
| 4083 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4084 | container_of(listener, struct desktop_shell, |
| 4085 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4086 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4087 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4088 | shell->text_input.surface = (struct weston_surface*)data; |
| 4089 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4090 | if (shell->showing_input_panels) |
| 4091 | return; |
| 4092 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4093 | shell->showing_input_panels = true; |
| 4094 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4095 | if (!shell->locked) |
| 4096 | wl_list_insert(&shell->panel_layer.link, |
| 4097 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4098 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4099 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4100 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4101 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4102 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4103 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4104 | &ipsurf->view->layer_link); |
| 4105 | weston_view_geometry_dirty(ipsurf->view); |
| 4106 | weston_view_update_transform(ipsurf->view); |
| 4107 | weston_surface_damage(ipsurf->surface); |
| 4108 | weston_slide_run(ipsurf->view, ipsurf->view->geometry.height, |
| 4109 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | static void |
| 4114 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4115 | { |
| 4116 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4117 | container_of(listener, struct desktop_shell, |
| 4118 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4119 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4120 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4121 | if (!shell->showing_input_panels) |
| 4122 | return; |
| 4123 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4124 | shell->showing_input_panels = false; |
| 4125 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4126 | if (!shell->locked) |
| 4127 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4128 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4129 | wl_list_for_each_safe(view, next, |
| 4130 | &shell->input_panel_layer.view_list, layer_link) |
| 4131 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4135 | update_input_panels(struct wl_listener *listener, void *data) |
| 4136 | { |
| 4137 | struct desktop_shell *shell = |
| 4138 | container_of(listener, struct desktop_shell, |
| 4139 | update_input_panel_listener); |
| 4140 | |
| 4141 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4142 | } |
| 4143 | |
| 4144 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4145 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4146 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4147 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4148 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4149 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4150 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4151 | |
| 4152 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4153 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4154 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4155 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4159 | weston_view_set_initial_position(struct weston_view *view, |
| 4160 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4161 | { |
| 4162 | struct weston_compositor *compositor = shell->compositor; |
| 4163 | int ix = 0, iy = 0; |
| 4164 | int range_x, range_y; |
| 4165 | int dx, dy, x, y, panel_height; |
| 4166 | struct weston_output *output, *target_output = NULL; |
| 4167 | struct weston_seat *seat; |
| 4168 | |
| 4169 | /* As a heuristic place the new window on the same output as the |
| 4170 | * pointer. Falling back to the output containing 0, 0. |
| 4171 | * |
| 4172 | * TODO: Do something clever for touch too? |
| 4173 | */ |
| 4174 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4175 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4176 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4177 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4178 | break; |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4183 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4184 | target_output = output; |
| 4185 | break; |
| 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4190 | weston_view_set_position(view, 10 + random() % 400, |
| 4191 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4192 | return; |
| 4193 | } |
| 4194 | |
| 4195 | /* Valid range within output where the surface will still be onscreen. |
| 4196 | * If this is negative it means that the surface is bigger than |
| 4197 | * output. |
| 4198 | */ |
| 4199 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4200 | range_x = target_output->width - view->geometry.width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4201 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4202 | view->geometry.height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4203 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4204 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4205 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4206 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4207 | dx = 0; |
| 4208 | |
| 4209 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4210 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4211 | else |
| 4212 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4213 | |
| 4214 | x = target_output->x + dx; |
| 4215 | y = target_output->y + dy; |
| 4216 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4217 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4221 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4222 | int32_t width, int32_t height, int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4223 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4224 | struct weston_compositor *compositor = shell->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4225 | struct weston_view *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4226 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4227 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4228 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4229 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4230 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4231 | shsurf->view->geometry.width = width; |
| 4232 | shsurf->view->geometry.height = height; |
| 4233 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4234 | |
| 4235 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4236 | switch (shsurf->type) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4237 | case SHELL_SURFACE_TOPLEVEL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4238 | weston_view_set_initial_position(shsurf->view, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4239 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4240 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4241 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4242 | shell_map_fullscreen(shsurf); |
| 4243 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4244 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4245 | /* use surface configure to set the geometry */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4246 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4247 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4248 | &surf_x, &surf_y, NULL, NULL); |
| 4249 | weston_view_set_position(shsurf->view, |
| 4250 | shsurf->output->x - surf_x, |
| 4251 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4252 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4253 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4254 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4255 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4256 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4257 | weston_view_set_position(shsurf->view, |
| 4258 | shsurf->view->geometry.x + sx, |
| 4259 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4260 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4261 | default: |
| 4262 | ; |
| 4263 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4264 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 4265 | /* surface stacking order, see also activate() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4266 | switch (shsurf->type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4267 | case SHELL_SURFACE_POPUP: |
| 4268 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4269 | /* TODO: Handle a parent with multiple views */ |
| 4270 | parent = get_default_view(shsurf->parent); |
| 4271 | if (parent) { |
| 4272 | wl_list_remove(&shsurf->view->layer_link); |
| 4273 | wl_list_insert(parent->layer_link.prev, |
| 4274 | &shsurf->view->layer_link); |
| 4275 | } |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4276 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4277 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 4278 | case SHELL_SURFACE_NONE: |
| 4279 | break; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4280 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4281 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4282 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4283 | wl_list_remove(&shsurf->view->layer_link); |
| 4284 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4285 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4286 | } |
| 4287 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4288 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4289 | weston_view_update_transform(shsurf->view); |
| 4290 | if (shsurf->type == SHELL_SURFACE_MAXIMIZED) { |
| 4291 | shsurf->surface->output = shsurf->output; |
| 4292 | shsurf->view->output = shsurf->output; |
| 4293 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4294 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4295 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4296 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4297 | /* XXX: xwayland's using the same fields for transient type */ |
| 4298 | case SHELL_SURFACE_XWAYLAND: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4299 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4300 | if (shsurf->transient.flags == |
| 4301 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4302 | break; |
| 4303 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4304 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4305 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4306 | if (!shell->locked) { |
| 4307 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4308 | activate(shell, shsurf->surface, seat); |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4309 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4310 | break; |
| 4311 | default: |
| 4312 | break; |
| 4313 | } |
| 4314 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4315 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4316 | { |
| 4317 | switch (shell->win_animation_type) { |
| 4318 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4319 | 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] | 4320 | break; |
| 4321 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4322 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4323 | break; |
| 4324 | default: |
| 4325 | break; |
| 4326 | } |
| 4327 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4331 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4332 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4333 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4334 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 4335 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4336 | struct weston_view *view; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4337 | int32_t surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4338 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4339 | shsurf = get_shell_surface(surface); |
| 4340 | if (shsurf) |
| 4341 | surface_type = shsurf->type; |
| 4342 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4343 | /* TODO: |
| 4344 | * This should probably be changed to be more shell_surface |
| 4345 | * dependent |
| 4346 | */ |
| 4347 | wl_list_for_each(view, &surface->views, surface_link) |
| 4348 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4349 | |
| 4350 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4351 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 4352 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4353 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4354 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4355 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4356 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4357 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4358 | NULL, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4359 | shsurf->view->geometry.x = shsurf->output->x - surf_x; |
| 4360 | shsurf->view->geometry.y = shsurf->output->y + |
| 4361 | get_output_panel_height(shell,shsurf->output) - surf_y; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4362 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4363 | case SHELL_SURFACE_TOPLEVEL: |
| 4364 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4365 | default: |
| 4366 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4367 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4368 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4369 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4370 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4371 | wl_list_for_each(view, &surface->views, surface_link) |
| 4372 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4373 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4374 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4375 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4376 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4377 | } |
| 4378 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4379 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4380 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4381 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4382 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4383 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4384 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4385 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4386 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4387 | if (!weston_surface_is_mapped(es) && |
| 4388 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4389 | remove_popup_grab(shsurf); |
| 4390 | } |
| 4391 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4392 | if (width == 0) |
| 4393 | return; |
| 4394 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4395 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4396 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4397 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4398 | type_changed = 1; |
| 4399 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4400 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4401 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4402 | map(shell, shsurf, width, height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4403 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4404 | shsurf->view->geometry.width != width || |
| 4405 | shsurf->view->geometry.height != height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4406 | float from_x, from_y; |
| 4407 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4408 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4409 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4410 | 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] | 4411 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4412 | shsurf->view->geometry.x + to_x - from_x, |
| 4413 | shsurf->view->geometry.y + to_y - from_y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4414 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4415 | } |
| 4416 | } |
| 4417 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4418 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4419 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4420 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4421 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4422 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4423 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4424 | struct desktop_shell *shell = |
| 4425 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4426 | |
| 4427 | shell->child.process.pid = 0; |
| 4428 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4429 | |
| 4430 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4431 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4432 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4433 | shell->child.deathstamp = time; |
| 4434 | shell->child.deathcount = 0; |
| 4435 | } |
| 4436 | |
| 4437 | shell->child.deathcount++; |
| 4438 | if (shell->child.deathcount > 5) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4439 | weston_log("weston-desktop-shell died, giving up.\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4440 | return; |
| 4441 | } |
| 4442 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4443 | weston_log("weston-desktop-shell died, respawning...\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4444 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4445 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4446 | } |
| 4447 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4448 | static void |
| 4449 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4450 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4451 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 4452 | const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4453 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4454 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4455 | &shell->child.process, |
| 4456 | shell_exe, |
| 4457 | desktop_shell_sigchld); |
| 4458 | |
| 4459 | if (!shell->child.client) |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4460 | weston_log("not able to start %s\n", shell_exe); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4461 | } |
| 4462 | |
| 4463 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4464 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4465 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4466 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4467 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4468 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4469 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4470 | if (resource) |
| 4471 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4472 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4473 | } |
| 4474 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4475 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4476 | unbind_desktop_shell(struct wl_resource *resource) |
| 4477 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4478 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4479 | |
| 4480 | if (shell->locked) |
| 4481 | resume_desktop(shell); |
| 4482 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4483 | shell->child.desktop_shell = NULL; |
| 4484 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4488 | bind_desktop_shell(struct wl_client *client, |
| 4489 | void *data, uint32_t version, uint32_t id) |
| 4490 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4491 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4492 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4493 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4494 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4495 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4496 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4497 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4498 | wl_resource_set_implementation(resource, |
| 4499 | &desktop_shell_implementation, |
| 4500 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4501 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4502 | |
| 4503 | if (version < 2) |
| 4504 | shell_fade_startup(shell); |
| 4505 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4506 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4507 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4508 | |
| 4509 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4510 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4511 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4512 | } |
| 4513 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4514 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4515 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4516 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4517 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4518 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4519 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4520 | if (width == 0) |
| 4521 | return; |
| 4522 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4523 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4524 | if (!shell->locked) |
| 4525 | return; |
| 4526 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4527 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4528 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4529 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4530 | if (wl_list_empty(&view->layer_link)) { |
| 4531 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4532 | &view->layer_link); |
| 4533 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4534 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4535 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4536 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4541 | screensaver_set_surface(struct wl_client *client, |
| 4542 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4543 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4544 | struct wl_resource *output_resource) |
| 4545 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4546 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4547 | struct weston_surface *surface = |
| 4548 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4549 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4550 | struct weston_view *view, *next; |
| 4551 | |
| 4552 | /* Make sure we only have one view */ |
| 4553 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4554 | weston_view_destroy(view); |
| 4555 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4556 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4557 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4558 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4559 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4560 | } |
| 4561 | |
| 4562 | static const struct screensaver_interface screensaver_implementation = { |
| 4563 | screensaver_set_surface |
| 4564 | }; |
| 4565 | |
| 4566 | static void |
| 4567 | unbind_screensaver(struct wl_resource *resource) |
| 4568 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4569 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4570 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4571 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4572 | } |
| 4573 | |
| 4574 | static void |
| 4575 | bind_screensaver(struct wl_client *client, |
| 4576 | void *data, uint32_t version, uint32_t id) |
| 4577 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4578 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4579 | struct wl_resource *resource; |
| 4580 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4581 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4582 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4583 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4584 | wl_resource_set_implementation(resource, |
| 4585 | &screensaver_implementation, |
| 4586 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4587 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4588 | return; |
| 4589 | } |
| 4590 | |
| 4591 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4592 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4593 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4594 | } |
| 4595 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4596 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4597 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4598 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4599 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4600 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4601 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4602 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4603 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4604 | if (width == 0) |
| 4605 | return; |
| 4606 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4607 | if (!weston_surface_is_mapped(surface)) { |
| 4608 | if (!shell->showing_input_panels) |
| 4609 | return; |
| 4610 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4611 | show_surface = 1; |
| 4612 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4613 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4614 | 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] | 4615 | |
| 4616 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4617 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4618 | 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] | 4619 | } else { |
Rob Bradford | bdeb5d2 | 2013-07-11 13:20:53 +0100 | [diff] [blame] | 4620 | x = ip_surface->output->x + (ip_surface->output->width - width) / 2; |
| 4621 | y = ip_surface->output->y + ip_surface->output->height - height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4622 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4623 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4624 | weston_view_configure(ip_surface->view, x, y, width, height); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4625 | |
| 4626 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4627 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4628 | &ip_surface->view->layer_link); |
| 4629 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4630 | weston_surface_damage(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4631 | weston_slide_run(ip_surface->view, ip_surface->view->geometry.height, 0, NULL, NULL); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4632 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4636 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4637 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4638 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4639 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4640 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4641 | wl_list_remove(&input_panel_surface->link); |
| 4642 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4643 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4644 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4645 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4646 | free(input_panel_surface); |
| 4647 | } |
| 4648 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4649 | static struct input_panel_surface * |
| 4650 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4651 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4652 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4653 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4654 | } else { |
| 4655 | return NULL; |
| 4656 | } |
| 4657 | } |
| 4658 | |
| 4659 | static void |
| 4660 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4661 | { |
| 4662 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4663 | struct input_panel_surface, |
| 4664 | surface_destroy_listener); |
| 4665 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4666 | if (ipsurface->resource) { |
| 4667 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4668 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4669 | destroy_input_panel_surface(ipsurface); |
| 4670 | } |
| 4671 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4672 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4673 | static struct input_panel_surface * |
| 4674 | create_input_panel_surface(struct desktop_shell *shell, |
| 4675 | struct weston_surface *surface) |
| 4676 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4677 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4678 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4679 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4680 | if (!input_panel_surface) |
| 4681 | return NULL; |
| 4682 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4683 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4684 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4685 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4686 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4687 | |
| 4688 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4689 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4690 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4691 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4692 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4693 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4694 | &input_panel_surface->surface_destroy_listener); |
| 4695 | |
| 4696 | wl_list_init(&input_panel_surface->link); |
| 4697 | |
| 4698 | return input_panel_surface; |
| 4699 | } |
| 4700 | |
| 4701 | static void |
| 4702 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4703 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4704 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4705 | uint32_t position) |
| 4706 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4707 | struct input_panel_surface *input_panel_surface = |
| 4708 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4709 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4710 | |
| 4711 | wl_list_insert(&shell->input_panel.surfaces, |
| 4712 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4713 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4714 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4715 | input_panel_surface->panel = 0; |
| 4716 | } |
| 4717 | |
| 4718 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4719 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4720 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4721 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4722 | struct input_panel_surface *input_panel_surface = |
| 4723 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4724 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4725 | |
| 4726 | wl_list_insert(&shell->input_panel.surfaces, |
| 4727 | &input_panel_surface->link); |
| 4728 | |
| 4729 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4730 | } |
| 4731 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4732 | 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] | 4733 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4734 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4735 | }; |
| 4736 | |
| 4737 | static void |
| 4738 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4739 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4740 | struct input_panel_surface *ipsurf = |
| 4741 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4742 | |
| 4743 | destroy_input_panel_surface(ipsurf); |
| 4744 | } |
| 4745 | |
| 4746 | static void |
| 4747 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4748 | struct wl_resource *resource, |
| 4749 | uint32_t id, |
| 4750 | struct wl_resource *surface_resource) |
| 4751 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4752 | struct weston_surface *surface = |
| 4753 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4754 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4755 | struct input_panel_surface *ipsurf; |
| 4756 | |
| 4757 | if (get_input_panel_surface(surface)) { |
| 4758 | wl_resource_post_error(surface_resource, |
| 4759 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4760 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4761 | return; |
| 4762 | } |
| 4763 | |
| 4764 | ipsurf = create_input_panel_surface(shell, surface); |
| 4765 | if (!ipsurf) { |
| 4766 | wl_resource_post_error(surface_resource, |
| 4767 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4768 | "surface->configure already set"); |
| 4769 | return; |
| 4770 | } |
| 4771 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4772 | ipsurf->resource = |
| 4773 | wl_resource_create(client, |
| 4774 | &wl_input_panel_surface_interface, 1, id); |
| 4775 | wl_resource_set_implementation(ipsurf->resource, |
| 4776 | &input_panel_surface_implementation, |
| 4777 | ipsurf, |
| 4778 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4779 | } |
| 4780 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4781 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4782 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4783 | }; |
| 4784 | |
| 4785 | static void |
| 4786 | unbind_input_panel(struct wl_resource *resource) |
| 4787 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4788 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4789 | |
| 4790 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | static void |
| 4794 | bind_input_panel(struct wl_client *client, |
| 4795 | void *data, uint32_t version, uint32_t id) |
| 4796 | { |
| 4797 | struct desktop_shell *shell = data; |
| 4798 | struct wl_resource *resource; |
| 4799 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4800 | resource = wl_resource_create(client, |
| 4801 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4802 | |
| 4803 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4804 | wl_resource_set_implementation(resource, |
| 4805 | &input_panel_implementation, |
| 4806 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4807 | shell->input_panel.binding = resource; |
| 4808 | return; |
| 4809 | } |
| 4810 | |
| 4811 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4812 | "interface object already bound"); |
| 4813 | wl_resource_destroy(resource); |
| 4814 | } |
| 4815 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4816 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4817 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4818 | struct weston_surface *current; |
| 4819 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4820 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4821 | }; |
| 4822 | |
| 4823 | static void |
| 4824 | switcher_next(struct switcher *switcher) |
| 4825 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4826 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4827 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4828 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4829 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4830 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4831 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 4832 | switch (get_shell_surface_type(view->surface)) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4833 | case SHELL_SURFACE_TOPLEVEL: |
| 4834 | case SHELL_SURFACE_FULLSCREEN: |
| 4835 | case SHELL_SURFACE_MAXIMIZED: |
| 4836 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4837 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4838 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4839 | next = view->surface; |
| 4840 | prev = view->surface; |
| 4841 | view->alpha = 0.25; |
| 4842 | weston_view_geometry_dirty(view); |
| 4843 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4844 | break; |
| 4845 | default: |
| 4846 | break; |
| 4847 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4848 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4849 | if (is_black_surface(view->surface, NULL)) { |
| 4850 | view->alpha = 0.25; |
| 4851 | weston_view_geometry_dirty(view); |
| 4852 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4853 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | if (next == NULL) |
| 4857 | next = first; |
| 4858 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4859 | if (next == NULL) |
| 4860 | return; |
| 4861 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4862 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4863 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4864 | |
| 4865 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4866 | wl_list_for_each(view, &next->views, surface_link) |
| 4867 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4868 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4869 | shsurf = get_shell_surface(switcher->current); |
| 4870 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4871 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4875 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4876 | { |
| 4877 | struct switcher *switcher = |
| 4878 | container_of(listener, struct switcher, listener); |
| 4879 | |
| 4880 | switcher_next(switcher); |
| 4881 | } |
| 4882 | |
| 4883 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4884 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4885 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4886 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4887 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4888 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4889 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4890 | 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] | 4891 | if (is_focus_view(view)) |
| 4892 | continue; |
| 4893 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4894 | view->alpha = 1.0; |
| 4895 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4896 | } |
| 4897 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4898 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4899 | activate(switcher->shell, switcher->current, |
| 4900 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4901 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4902 | weston_keyboard_end_grab(keyboard); |
| 4903 | if (keyboard->input_method_resource) |
| 4904 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4905 | free(switcher); |
| 4906 | } |
| 4907 | |
| 4908 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4909 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4910 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4911 | { |
| 4912 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4913 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4914 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4915 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4916 | switcher_next(switcher); |
| 4917 | } |
| 4918 | |
| 4919 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4920 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4921 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4922 | uint32_t mods_locked, uint32_t group) |
| 4923 | { |
| 4924 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4925 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4926 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4927 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4928 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4929 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4930 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4931 | static void |
| 4932 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4933 | { |
| 4934 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4935 | |
| 4936 | switcher_destroy(switcher); |
| 4937 | } |
| 4938 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4939 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4940 | switcher_key, |
| 4941 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4942 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4943 | }; |
| 4944 | |
| 4945 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4946 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4947 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4948 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4949 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4950 | struct switcher *switcher; |
| 4951 | |
| 4952 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4953 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4954 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4955 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4956 | wl_list_init(&switcher->listener.link); |
| 4957 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4958 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4959 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4960 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4961 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 4962 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4963 | switcher_next(switcher); |
| 4964 | } |
| 4965 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 4966 | struct exposay_surface { |
| 4967 | struct desktop_shell *shell; |
| 4968 | struct weston_surface *surface; |
| 4969 | struct weston_view *view; |
| 4970 | struct wl_list link; |
| 4971 | |
| 4972 | int x; |
| 4973 | int y; |
| 4974 | int width; |
| 4975 | int height; |
| 4976 | double scale; |
| 4977 | |
| 4978 | int row; |
| 4979 | int column; |
| 4980 | |
| 4981 | /* The animations only apply a transformation for their own lifetime, |
| 4982 | * and don't have an option to indefinitely maintain the |
| 4983 | * transformation in a steady state - so, we apply our own once the |
| 4984 | * animation has finished. */ |
| 4985 | struct weston_transform transform; |
| 4986 | }; |
| 4987 | |
| 4988 | static void exposay_set_state(struct desktop_shell *shell, |
| 4989 | enum exposay_target_state state, |
| 4990 | struct weston_seat *seat); |
| 4991 | static void exposay_check_state(struct desktop_shell *shell); |
| 4992 | |
| 4993 | static void |
| 4994 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 4995 | { |
| 4996 | shell->exposay.in_flight++; |
| 4997 | } |
| 4998 | |
| 4999 | static void |
| 5000 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5001 | { |
| 5002 | if (--shell->exposay.in_flight > 0) |
| 5003 | return; |
| 5004 | |
| 5005 | exposay_check_state(shell); |
| 5006 | } |
| 5007 | |
| 5008 | static void |
| 5009 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5010 | { |
| 5011 | struct exposay_surface *esurface = data; |
| 5012 | |
| 5013 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5014 | &esurface->transform.link); |
| 5015 | weston_matrix_init(&esurface->transform.matrix); |
| 5016 | weston_matrix_scale(&esurface->transform.matrix, |
| 5017 | esurface->scale, esurface->scale, 1.0f); |
| 5018 | weston_matrix_translate(&esurface->transform.matrix, |
| 5019 | esurface->x - esurface->view->geometry.x, |
| 5020 | esurface->y - esurface->view->geometry.y, |
| 5021 | 0); |
| 5022 | |
| 5023 | weston_view_geometry_dirty(esurface->view); |
| 5024 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5025 | |
| 5026 | exposay_in_flight_dec(esurface->shell); |
| 5027 | } |
| 5028 | |
| 5029 | static void |
| 5030 | exposay_animate_in(struct exposay_surface *esurface) |
| 5031 | { |
| 5032 | exposay_in_flight_inc(esurface->shell); |
| 5033 | |
| 5034 | weston_move_scale_run(esurface->view, |
| 5035 | esurface->x - esurface->view->geometry.x, |
| 5036 | esurface->y - esurface->view->geometry.y, |
| 5037 | 1.0, esurface->scale, 0, |
| 5038 | exposay_animate_in_done, esurface); |
| 5039 | } |
| 5040 | |
| 5041 | static void |
| 5042 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5043 | { |
| 5044 | struct exposay_surface *esurface = data; |
| 5045 | struct desktop_shell *shell = esurface->shell; |
| 5046 | |
| 5047 | wl_list_remove(&esurface->link); |
| 5048 | free(esurface); |
| 5049 | |
| 5050 | exposay_in_flight_dec(shell); |
| 5051 | } |
| 5052 | |
| 5053 | static void |
| 5054 | exposay_animate_out(struct exposay_surface *esurface) |
| 5055 | { |
| 5056 | exposay_in_flight_inc(esurface->shell); |
| 5057 | |
| 5058 | /* Remove the static transformation set up by |
| 5059 | * exposay_transform_in_done(). */ |
| 5060 | wl_list_remove(&esurface->transform.link); |
| 5061 | weston_view_geometry_dirty(esurface->view); |
| 5062 | |
| 5063 | weston_move_scale_run(esurface->view, |
| 5064 | esurface->x - esurface->view->geometry.x, |
| 5065 | esurface->y - esurface->view->geometry.y, |
| 5066 | 1.0, esurface->scale, 1, |
| 5067 | exposay_animate_out_done, esurface); |
| 5068 | } |
| 5069 | |
| 5070 | static void |
| 5071 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5072 | struct exposay_surface *esurface) |
| 5073 | { |
| 5074 | struct weston_view *view = NULL; |
| 5075 | |
| 5076 | if (esurface) { |
| 5077 | shell->exposay.row_current = esurface->row; |
| 5078 | shell->exposay.column_current = esurface->column; |
| 5079 | view = esurface->view; |
| 5080 | } |
| 5081 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5082 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5083 | shell->exposay.focus_current = view; |
| 5084 | } |
| 5085 | |
| 5086 | static int |
| 5087 | exposay_is_animating(struct desktop_shell *shell) |
| 5088 | { |
| 5089 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5090 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5091 | return 0; |
| 5092 | |
| 5093 | return (shell->exposay.in_flight > 0); |
| 5094 | } |
| 5095 | |
| 5096 | static void |
| 5097 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5098 | { |
| 5099 | struct exposay_surface *esurface; |
| 5100 | |
| 5101 | if (exposay_is_animating(shell)) |
| 5102 | return; |
| 5103 | |
| 5104 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5105 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5106 | continue; |
| 5107 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5108 | continue; |
| 5109 | |
| 5110 | exposay_highlight_surface(shell, esurface); |
| 5111 | return; |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5116 | * aspect ratio into account really. Also needs to be notified of surface |
| 5117 | * addition and removal and adjust layout/animate accordingly. */ |
| 5118 | static enum exposay_layout_state |
| 5119 | exposay_layout(struct desktop_shell *shell) |
| 5120 | { |
| 5121 | struct workspace *workspace = shell->exposay.workspace; |
| 5122 | struct weston_compositor *compositor = shell->compositor; |
| 5123 | struct weston_output *output = get_default_output(compositor); |
| 5124 | struct weston_view *view; |
| 5125 | struct exposay_surface *esurface; |
| 5126 | int w, h; |
| 5127 | int i; |
| 5128 | int last_row_removed = 0; |
| 5129 | |
| 5130 | wl_list_init(&shell->exposay.surface_list); |
| 5131 | |
| 5132 | shell->exposay.num_surfaces = 0; |
| 5133 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5134 | if (!get_shell_surface(view->surface)) |
| 5135 | continue; |
| 5136 | shell->exposay.num_surfaces++; |
| 5137 | } |
| 5138 | |
| 5139 | if (shell->exposay.num_surfaces == 0) { |
| 5140 | shell->exposay.grid_size = 0; |
| 5141 | shell->exposay.hpadding_outer = 0; |
| 5142 | shell->exposay.vpadding_outer = 0; |
| 5143 | shell->exposay.padding_inner = 0; |
| 5144 | shell->exposay.surface_size = 0; |
| 5145 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5146 | } |
| 5147 | |
| 5148 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5149 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5150 | * around the outside and 80px internal padding between surfaces, and |
| 5151 | * maximise the area made available to surfaces after this, but only |
| 5152 | * to a maximum of 1/3rd the total output size. |
| 5153 | * |
| 5154 | * If we can't make a square grid, add one extra row at the bottom |
| 5155 | * which will have a smaller number of columns. |
| 5156 | * |
| 5157 | * XXX: Surely there has to be a better way to express this maths, |
| 5158 | * right?! |
| 5159 | */ |
| 5160 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5161 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5162 | shell->exposay.grid_size++; |
| 5163 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5164 | |
| 5165 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5166 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5167 | shell->exposay.padding_inner = 80; |
| 5168 | |
| 5169 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5170 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5171 | w /= shell->exposay.grid_size; |
| 5172 | |
| 5173 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5174 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5175 | h /= shell->exposay.grid_size; |
| 5176 | |
| 5177 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5178 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5179 | shell->exposay.surface_size = output->width / 2; |
| 5180 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5181 | shell->exposay.surface_size = output->height / 2; |
| 5182 | |
| 5183 | i = 0; |
| 5184 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5185 | int pad; |
| 5186 | |
| 5187 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5188 | |
| 5189 | if (!get_shell_surface(view->surface)) |
| 5190 | continue; |
| 5191 | |
| 5192 | esurface = malloc(sizeof(*esurface)); |
| 5193 | if (!esurface) { |
| 5194 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5195 | shell->exposay.seat); |
| 5196 | break; |
| 5197 | } |
| 5198 | |
| 5199 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5200 | esurface->shell = shell; |
| 5201 | esurface->view = view; |
| 5202 | |
| 5203 | esurface->row = i / shell->exposay.grid_size; |
| 5204 | esurface->column = i % shell->exposay.grid_size; |
| 5205 | |
| 5206 | esurface->x = shell->exposay.hpadding_outer; |
| 5207 | esurface->x += pad * esurface->column; |
| 5208 | esurface->y = shell->exposay.vpadding_outer; |
| 5209 | esurface->y += pad * esurface->row; |
| 5210 | |
| 5211 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5212 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5213 | |
| 5214 | if (view->geometry.width > view->geometry.height) |
| 5215 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.width; |
| 5216 | else |
| 5217 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.height; |
| 5218 | esurface->width = view->geometry.width * esurface->scale; |
| 5219 | esurface->height = view->geometry.height * esurface->scale; |
| 5220 | |
| 5221 | if (shell->exposay.focus_current == esurface->view) |
| 5222 | exposay_highlight_surface(shell, esurface); |
| 5223 | |
| 5224 | exposay_animate_in(esurface); |
| 5225 | |
| 5226 | i++; |
| 5227 | } |
| 5228 | |
| 5229 | weston_compositor_schedule_repaint(shell->compositor); |
| 5230 | |
| 5231 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5232 | } |
| 5233 | |
| 5234 | static void |
| 5235 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time) |
| 5236 | { |
| 5237 | struct desktop_shell *shell = |
| 5238 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5239 | |
| 5240 | exposay_pick(shell, |
| 5241 | wl_fixed_to_int(grab->pointer->x), |
| 5242 | wl_fixed_to_int(grab->pointer->y)); |
| 5243 | } |
| 5244 | |
| 5245 | static void |
| 5246 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5247 | uint32_t state_w) |
| 5248 | { |
| 5249 | struct desktop_shell *shell = |
| 5250 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5251 | struct weston_seat *seat = grab->pointer->seat; |
| 5252 | enum wl_pointer_button_state state = state_w; |
| 5253 | |
| 5254 | if (button != BTN_LEFT) |
| 5255 | return; |
| 5256 | |
| 5257 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5258 | * releasing on a different surface. */ |
| 5259 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5260 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5261 | return; |
| 5262 | } |
| 5263 | |
| 5264 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5265 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5266 | else |
| 5267 | shell->exposay.clicked = NULL; |
| 5268 | } |
| 5269 | |
| 5270 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5271 | noop_grab_focus, |
| 5272 | exposay_motion, |
| 5273 | exposay_button, |
| 5274 | }; |
| 5275 | |
| 5276 | static int |
| 5277 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5278 | { |
| 5279 | struct exposay_surface *esurface; |
| 5280 | |
| 5281 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5282 | if (esurface->row != row || esurface->column != column) |
| 5283 | continue; |
| 5284 | |
| 5285 | exposay_highlight_surface(shell, esurface); |
| 5286 | return 1; |
| 5287 | } |
| 5288 | |
| 5289 | return 0; |
| 5290 | } |
| 5291 | |
| 5292 | static void |
| 5293 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5294 | uint32_t state_w) |
| 5295 | { |
| 5296 | struct weston_seat *seat = grab->keyboard->seat; |
| 5297 | struct desktop_shell *shell = |
| 5298 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5299 | enum wl_keyboard_key_state state = state_w; |
| 5300 | |
| 5301 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5302 | return; |
| 5303 | |
| 5304 | switch (key) { |
| 5305 | case KEY_ESC: |
| 5306 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5307 | break; |
| 5308 | case KEY_ENTER: |
| 5309 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5310 | break; |
| 5311 | case KEY_UP: |
| 5312 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5313 | shell->exposay.column_current); |
| 5314 | break; |
| 5315 | case KEY_DOWN: |
| 5316 | /* Special case for trying to move to the bottom row when it |
| 5317 | * has fewer items than all the others. */ |
| 5318 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5319 | shell->exposay.column_current) && |
| 5320 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5321 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5322 | (shell->exposay.num_surfaces % |
| 5323 | shell->exposay.grid_size) - 1); |
| 5324 | } |
| 5325 | break; |
| 5326 | case KEY_LEFT: |
| 5327 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5328 | shell->exposay.column_current - 1); |
| 5329 | break; |
| 5330 | case KEY_RIGHT: |
| 5331 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5332 | shell->exposay.column_current + 1); |
| 5333 | break; |
| 5334 | case KEY_TAB: |
| 5335 | /* Try to move right, then down (and to the leftmost column), |
| 5336 | * then if all else fails, to the top left. */ |
| 5337 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5338 | shell->exposay.column_current + 1) && |
| 5339 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5340 | exposay_maybe_move(shell, 0, 0); |
| 5341 | break; |
| 5342 | default: |
| 5343 | break; |
| 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | static void |
| 5348 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5349 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5350 | uint32_t mods_locked, uint32_t group) |
| 5351 | { |
| 5352 | } |
| 5353 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5354 | static void |
| 5355 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 5356 | { |
| 5357 | struct desktop_shell *shell = |
| 5358 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5359 | |
| 5360 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 5361 | } |
| 5362 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5363 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5364 | exposay_key, |
| 5365 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 5366 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5367 | }; |
| 5368 | |
| 5369 | /** |
| 5370 | * Called when the transition from overview -> inactive has completed. |
| 5371 | */ |
| 5372 | static enum exposay_layout_state |
| 5373 | exposay_set_inactive(struct desktop_shell *shell) |
| 5374 | { |
| 5375 | struct weston_seat *seat = shell->exposay.seat; |
| 5376 | |
| 5377 | weston_keyboard_end_grab(seat->keyboard); |
| 5378 | weston_pointer_end_grab(seat->pointer); |
| 5379 | if (seat->keyboard->input_method_resource) |
| 5380 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5381 | |
| 5382 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5383 | } |
| 5384 | |
| 5385 | /** |
| 5386 | * Begins the transition from overview to inactive. */ |
| 5387 | static enum exposay_layout_state |
| 5388 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5389 | { |
| 5390 | struct exposay_surface *esurface; |
| 5391 | |
| 5392 | /* Call activate() before we start the animations to avoid |
| 5393 | * animating back the old state and then immediately transitioning |
| 5394 | * to the new. */ |
| 5395 | if (switch_focus && shell->exposay.focus_current) |
| 5396 | activate(shell, shell->exposay.focus_current->surface, |
| 5397 | shell->exposay.seat); |
| 5398 | else if (shell->exposay.focus_prev) |
| 5399 | activate(shell, shell->exposay.focus_prev->surface, |
| 5400 | shell->exposay.seat); |
| 5401 | |
| 5402 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5403 | exposay_animate_out(esurface); |
| 5404 | weston_compositor_schedule_repaint(shell->compositor); |
| 5405 | |
| 5406 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5407 | } |
| 5408 | |
| 5409 | static enum exposay_layout_state |
| 5410 | exposay_transition_active(struct desktop_shell *shell) |
| 5411 | { |
| 5412 | struct weston_seat *seat = shell->exposay.seat; |
| 5413 | |
| 5414 | shell->exposay.workspace = get_current_workspace(shell); |
| 5415 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5416 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5417 | shell->exposay.clicked = NULL; |
| 5418 | wl_list_init(&shell->exposay.surface_list); |
| 5419 | |
| 5420 | lower_fullscreen_layer(shell); |
| 5421 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5422 | weston_keyboard_start_grab(seat->keyboard, |
| 5423 | &shell->exposay.grab_kbd); |
| 5424 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5425 | |
| 5426 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5427 | weston_pointer_start_grab(seat->pointer, |
| 5428 | &shell->exposay.grab_ptr); |
| 5429 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5430 | seat->pointer->x, seat->pointer->y); |
| 5431 | |
| 5432 | return exposay_layout(shell); |
| 5433 | } |
| 5434 | |
| 5435 | static void |
| 5436 | exposay_check_state(struct desktop_shell *shell) |
| 5437 | { |
| 5438 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5439 | int do_switch = 0; |
| 5440 | |
| 5441 | /* Don't do anything whilst animations are running, just store up |
| 5442 | * target state changes and only act on them when the animations have |
| 5443 | * completed. */ |
| 5444 | if (exposay_is_animating(shell)) |
| 5445 | return; |
| 5446 | |
| 5447 | switch (shell->exposay.state_target) { |
| 5448 | case EXPOSAY_TARGET_OVERVIEW: |
| 5449 | switch (shell->exposay.state_cur) { |
| 5450 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5451 | goto out; |
| 5452 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5453 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5454 | break; |
| 5455 | default: |
| 5456 | state_new = exposay_transition_active(shell); |
| 5457 | break; |
| 5458 | } |
| 5459 | break; |
| 5460 | |
| 5461 | case EXPOSAY_TARGET_SWITCH: |
| 5462 | do_switch = 1; /* fallthrough */ |
| 5463 | case EXPOSAY_TARGET_CANCEL: |
| 5464 | switch (shell->exposay.state_cur) { |
| 5465 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5466 | goto out; |
| 5467 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5468 | state_new = exposay_set_inactive(shell); |
| 5469 | break; |
| 5470 | default: |
| 5471 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5472 | break; |
| 5473 | } |
| 5474 | |
| 5475 | break; |
| 5476 | } |
| 5477 | |
| 5478 | out: |
| 5479 | shell->exposay.state_cur = state_new; |
| 5480 | } |
| 5481 | |
| 5482 | static void |
| 5483 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5484 | struct weston_seat *seat) |
| 5485 | { |
| 5486 | shell->exposay.state_target = state; |
| 5487 | shell->exposay.seat = seat; |
| 5488 | exposay_check_state(shell); |
| 5489 | } |
| 5490 | |
| 5491 | static void |
| 5492 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5493 | void *data) |
| 5494 | { |
| 5495 | struct desktop_shell *shell = data; |
| 5496 | |
| 5497 | if (shell->exposay.state_target == EXPOSAY_TARGET_OVERVIEW) |
| 5498 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5499 | else |
| 5500 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
| 5501 | } |
| 5502 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5503 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5504 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5505 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5506 | { |
| 5507 | struct weston_compositor *compositor = data; |
| 5508 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5509 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5510 | |
| 5511 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5512 | * control on the primary display. We'd have to extend later if we |
| 5513 | * ever get support for setting backlights on random desktop LCD |
| 5514 | * panels though */ |
| 5515 | output = get_default_output(compositor); |
| 5516 | if (!output) |
| 5517 | return; |
| 5518 | |
| 5519 | if (!output->set_backlight) |
| 5520 | return; |
| 5521 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5522 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5523 | backlight_new = output->backlight_current - 25; |
| 5524 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5525 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5526 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5527 | if (backlight_new < 5) |
| 5528 | backlight_new = 5; |
| 5529 | if (backlight_new > 255) |
| 5530 | backlight_new = 255; |
| 5531 | |
| 5532 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5533 | output->set_backlight(output, output->backlight_current); |
| 5534 | } |
| 5535 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5536 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5537 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5538 | struct weston_seat *seat; |
| 5539 | uint32_t key[2]; |
| 5540 | int key_released[2]; |
| 5541 | }; |
| 5542 | |
| 5543 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5544 | 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] | 5545 | uint32_t key, uint32_t state) |
| 5546 | { |
| 5547 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5548 | struct weston_compositor *ec = db->seat->compositor; |
| 5549 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5550 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5551 | uint32_t serial; |
| 5552 | int send = 0, terminate = 0; |
| 5553 | int check_binding = 1; |
| 5554 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5555 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5556 | |
| 5557 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5558 | /* Do not run bindings on key releases */ |
| 5559 | check_binding = 0; |
| 5560 | |
| 5561 | for (i = 0; i < 2; i++) |
| 5562 | if (key == db->key[i]) |
| 5563 | db->key_released[i] = 1; |
| 5564 | |
| 5565 | if (db->key_released[0] && db->key_released[1]) { |
| 5566 | /* All key releases been swalled so end the grab */ |
| 5567 | terminate = 1; |
| 5568 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5569 | /* Should not swallow release of other keys */ |
| 5570 | send = 1; |
| 5571 | } |
| 5572 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5573 | /* Do not check bindings for the first press of the binding |
| 5574 | * key. This allows it to be used as a debug shortcut. |
| 5575 | * We still need to swallow this event. */ |
| 5576 | check_binding = 0; |
| 5577 | } else if (db->key[1]) { |
| 5578 | /* If we already ran a binding don't process another one since |
| 5579 | * we can't keep track of all the binding keys that were |
| 5580 | * pressed in order to swallow the release events. */ |
| 5581 | send = 1; |
| 5582 | check_binding = 0; |
| 5583 | } |
| 5584 | |
| 5585 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5586 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5587 | key, state)) { |
| 5588 | /* We ran a binding so swallow the press and keep the |
| 5589 | * grab to swallow the released too. */ |
| 5590 | send = 0; |
| 5591 | terminate = 0; |
| 5592 | db->key[1] = key; |
| 5593 | } else { |
| 5594 | /* Terminate the grab since the key pressed is not a |
| 5595 | * debug binding key. */ |
| 5596 | send = 1; |
| 5597 | terminate = 1; |
| 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5602 | serial = wl_display_next_serial(display); |
| 5603 | resource_list = &grab->keyboard->focus_resource_list; |
| 5604 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5605 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5610 | weston_keyboard_end_grab(grab->keyboard); |
| 5611 | if (grab->keyboard->input_method_resource) |
| 5612 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5613 | free(db); |
| 5614 | } |
| 5615 | } |
| 5616 | |
| 5617 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5618 | 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] | 5619 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5620 | uint32_t mods_locked, uint32_t group) |
| 5621 | { |
| 5622 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5623 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5624 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5625 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5626 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5627 | wl_resource_for_each(resource, resource_list) { |
| 5628 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5629 | mods_latched, mods_locked, group); |
| 5630 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5631 | } |
| 5632 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5633 | static void |
| 5634 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5635 | { |
| 5636 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5637 | |
| 5638 | weston_keyboard_end_grab(grab->keyboard); |
| 5639 | free(db); |
| 5640 | } |
| 5641 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5642 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5643 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5644 | debug_binding_modifiers, |
| 5645 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5646 | }; |
| 5647 | |
| 5648 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5649 | 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] | 5650 | { |
| 5651 | struct debug_binding_grab *grab; |
| 5652 | |
| 5653 | grab = calloc(1, sizeof *grab); |
| 5654 | if (!grab) |
| 5655 | return; |
| 5656 | |
| 5657 | grab->seat = (struct weston_seat *) seat; |
| 5658 | grab->key[0] = key; |
| 5659 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5660 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5661 | } |
| 5662 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5663 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5664 | 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] | 5665 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5666 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5667 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5668 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5669 | struct desktop_shell *shell = data; |
| 5670 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5671 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5672 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5673 | focus_surface = seat->keyboard->focus; |
| 5674 | if (!focus_surface) |
| 5675 | return; |
| 5676 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5677 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5678 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5679 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5680 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5681 | |
| 5682 | /* Skip clients that we launched ourselves (the credentials of |
| 5683 | * the socketpair is ours) */ |
| 5684 | if (pid == getpid()) |
| 5685 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5686 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5687 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5691 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5692 | uint32_t key, void *data) |
| 5693 | { |
| 5694 | struct desktop_shell *shell = data; |
| 5695 | unsigned int new_index = shell->workspaces.current; |
| 5696 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5697 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5698 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5699 | if (new_index != 0) |
| 5700 | new_index--; |
| 5701 | |
| 5702 | change_workspace(shell, new_index); |
| 5703 | } |
| 5704 | |
| 5705 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5706 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5707 | uint32_t key, void *data) |
| 5708 | { |
| 5709 | struct desktop_shell *shell = data; |
| 5710 | unsigned int new_index = shell->workspaces.current; |
| 5711 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5712 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5713 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5714 | if (new_index < shell->workspaces.num - 1) |
| 5715 | new_index++; |
| 5716 | |
| 5717 | change_workspace(shell, new_index); |
| 5718 | } |
| 5719 | |
| 5720 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5721 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5722 | uint32_t key, void *data) |
| 5723 | { |
| 5724 | struct desktop_shell *shell = data; |
| 5725 | unsigned int new_index; |
| 5726 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5727 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5728 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5729 | new_index = key - KEY_F1; |
| 5730 | if (new_index >= shell->workspaces.num) |
| 5731 | new_index = shell->workspaces.num - 1; |
| 5732 | |
| 5733 | change_workspace(shell, new_index); |
| 5734 | } |
| 5735 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5736 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5737 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5738 | uint32_t key, void *data) |
| 5739 | { |
| 5740 | struct desktop_shell *shell = data; |
| 5741 | unsigned int new_index = shell->workspaces.current; |
| 5742 | |
| 5743 | if (shell->locked) |
| 5744 | return; |
| 5745 | |
| 5746 | if (new_index != 0) |
| 5747 | new_index--; |
| 5748 | |
| 5749 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5750 | } |
| 5751 | |
| 5752 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5753 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5754 | uint32_t key, void *data) |
| 5755 | { |
| 5756 | struct desktop_shell *shell = data; |
| 5757 | unsigned int new_index = shell->workspaces.current; |
| 5758 | |
| 5759 | if (shell->locked) |
| 5760 | return; |
| 5761 | |
| 5762 | if (new_index < shell->workspaces.num - 1) |
| 5763 | new_index++; |
| 5764 | |
| 5765 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5766 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5767 | |
| 5768 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5769 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5770 | { |
| 5771 | struct shell_output *output_listener = |
| 5772 | container_of(listener, struct shell_output, destroy_listener); |
| 5773 | |
| 5774 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5775 | wl_list_remove(&output_listener->link); |
| 5776 | free(output_listener); |
| 5777 | } |
| 5778 | |
| 5779 | static void |
| 5780 | create_shell_output(struct desktop_shell *shell, |
| 5781 | struct weston_output *output) |
| 5782 | { |
| 5783 | struct shell_output *shell_output; |
| 5784 | |
| 5785 | shell_output = zalloc(sizeof *shell_output); |
| 5786 | if (shell_output == NULL) |
| 5787 | return; |
| 5788 | |
| 5789 | shell_output->output = output; |
| 5790 | shell_output->shell = shell; |
| 5791 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5792 | wl_signal_add(&output->destroy_signal, |
| 5793 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5794 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | static void |
| 5798 | handle_output_create(struct wl_listener *listener, void *data) |
| 5799 | { |
| 5800 | struct desktop_shell *shell = |
| 5801 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5802 | struct weston_output *output = (struct weston_output *)data; |
| 5803 | |
| 5804 | create_shell_output(shell, output); |
| 5805 | } |
| 5806 | |
| 5807 | static void |
| 5808 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5809 | struct desktop_shell *shell) |
| 5810 | { |
| 5811 | struct weston_output *output; |
| 5812 | |
| 5813 | wl_list_init(&shell->output_list); |
| 5814 | wl_list_for_each(output, &ec->output_list, link) |
| 5815 | create_shell_output(shell, output); |
| 5816 | |
| 5817 | shell->output_create_listener.notify = handle_output_create; |
| 5818 | wl_signal_add(&ec->output_created_signal, |
| 5819 | &shell->output_create_listener); |
| 5820 | } |
| 5821 | |
| 5822 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5823 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5824 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5825 | struct desktop_shell *shell = |
| 5826 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5827 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5828 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5829 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5830 | if (shell->child.client) |
| 5831 | wl_client_destroy(shell->child.client); |
| 5832 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5833 | wl_list_remove(&shell->idle_listener.link); |
| 5834 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5835 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 5836 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5837 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5838 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5839 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5840 | wl_list_remove(&shell_output->link); |
| 5841 | free(shell_output); |
| 5842 | } |
| 5843 | |
| 5844 | wl_list_remove(&shell->output_create_listener.link); |
| 5845 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5846 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5847 | workspace_destroy(*ws); |
| 5848 | wl_array_release(&shell->workspaces.array); |
| 5849 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5850 | free(shell->screensaver.path); |
| 5851 | free(shell); |
| 5852 | } |
| 5853 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5854 | static void |
| 5855 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5856 | { |
| 5857 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5858 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5859 | |
| 5860 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5861 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5862 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5863 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 5864 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 5865 | MODIFIER_ALT, |
| 5866 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5867 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5868 | click_to_activate_binding, |
| 5869 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5870 | weston_compositor_add_touch_binding(ec, 0, |
| 5871 | touch_to_activate_binding, |
| 5872 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5873 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5874 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5875 | surface_opacity_binding, NULL); |
| 5876 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5877 | MODIFIER_SUPER, zoom_axis_binding, |
| 5878 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5879 | |
| 5880 | /* configurable bindings */ |
| 5881 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5882 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5883 | zoom_key_binding, NULL); |
| 5884 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5885 | zoom_key_binding, NULL); |
| 5886 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5887 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5888 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5889 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5890 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5891 | |
| 5892 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5893 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5894 | rotate_binding, NULL); |
| 5895 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5896 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5897 | shell); |
| 5898 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5899 | ec); |
| 5900 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5901 | backlight_binding, ec); |
| 5902 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5903 | ec); |
| 5904 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5905 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5906 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5907 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5908 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5909 | workspace_up_binding, shell); |
| 5910 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5911 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5912 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5913 | workspace_move_surface_up_binding, |
| 5914 | shell); |
| 5915 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5916 | workspace_move_surface_down_binding, |
| 5917 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5918 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5919 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 5920 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5921 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5922 | if (shell->workspaces.num > 1) { |
| 5923 | num_workspace_bindings = shell->workspaces.num; |
| 5924 | if (num_workspace_bindings > 6) |
| 5925 | num_workspace_bindings = 6; |
| 5926 | for (i = 0; i < num_workspace_bindings; i++) |
| 5927 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5928 | workspace_f_binding, |
| 5929 | shell); |
| 5930 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5931 | |
| 5932 | /* Debug bindings */ |
| 5933 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5934 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5935 | } |
| 5936 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5937 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5938 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5939 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5940 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5941 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5942 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5943 | struct workspace **pws; |
| 5944 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5945 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5946 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5947 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5948 | if (shell == NULL) |
| 5949 | return -1; |
| 5950 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5951 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5952 | |
| 5953 | shell->destroy_listener.notify = shell_destroy; |
| 5954 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5955 | shell->idle_listener.notify = idle_handler; |
| 5956 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5957 | shell->wake_listener.notify = wake_handler; |
| 5958 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5959 | shell->show_input_panel_listener.notify = show_input_panels; |
| 5960 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 5961 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 5962 | 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] | 5963 | shell->update_input_panel_listener.notify = update_input_panels; |
| 5964 | 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] | 5965 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5966 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5967 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5968 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5969 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5970 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5971 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5972 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5973 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5974 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5975 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5976 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5977 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5978 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5979 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5980 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5981 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5982 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5983 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5984 | |
| 5985 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5986 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5987 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5988 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5989 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5990 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5991 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5992 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5993 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5994 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5995 | if (pws == NULL) |
| 5996 | return -1; |
| 5997 | |
| 5998 | *pws = workspace_create(); |
| 5999 | if (*pws == NULL) |
| 6000 | return -1; |
| 6001 | } |
| 6002 | activate_workspace(shell, 0); |
| 6003 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6004 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6005 | wl_list_init(&shell->workspaces.animation.link); |
| 6006 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6007 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6008 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6009 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6010 | return -1; |
| 6011 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6012 | if (wl_global_create(ec->wl_display, |
| 6013 | &desktop_shell_interface, 2, |
| 6014 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6015 | return -1; |
| 6016 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6017 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6018 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6019 | return -1; |
| 6020 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6021 | 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] | 6022 | shell, bind_input_panel) == NULL) |
| 6023 | return -1; |
| 6024 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6025 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6026 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6027 | return -1; |
| 6028 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6029 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6030 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6031 | setup_output_destroy_handler(ec, shell); |
| 6032 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6033 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6034 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6035 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6036 | shell->screensaver.timer = |
| 6037 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6038 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6039 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6040 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6041 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6042 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6043 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6044 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6045 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6046 | return 0; |
| 6047 | } |