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); |
| 618 | |
| 619 | weston_view_configure(fsurf->view, output->x, output->y, |
| 620 | output->width, output->height); |
| 621 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 622 | pixman_region32_fini(&surface->opaque); |
| 623 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 624 | output->width, output->height); |
| 625 | pixman_region32_fini(&surface->input); |
| 626 | pixman_region32_init(&surface->input); |
| 627 | |
| 628 | wl_list_init(&fsurf->workspace_transform.link); |
| 629 | |
| 630 | return fsurf; |
| 631 | } |
| 632 | |
| 633 | static void |
| 634 | focus_surface_destroy(struct focus_surface *fsurf) |
| 635 | { |
| 636 | weston_surface_destroy(fsurf->surface); |
| 637 | free(fsurf); |
| 638 | } |
| 639 | |
| 640 | static void |
| 641 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 642 | { |
| 643 | struct workspace *ws = data; |
| 644 | |
| 645 | ws->focus_animation = NULL; |
| 646 | } |
| 647 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 648 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 649 | focus_state_destroy(struct focus_state *state) |
| 650 | { |
| 651 | wl_list_remove(&state->seat_destroy_listener.link); |
| 652 | wl_list_remove(&state->surface_destroy_listener.link); |
| 653 | free(state); |
| 654 | } |
| 655 | |
| 656 | static void |
| 657 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 658 | { |
| 659 | struct focus_state *state = container_of(listener, |
| 660 | struct focus_state, |
| 661 | seat_destroy_listener); |
| 662 | |
| 663 | wl_list_remove(&state->link); |
| 664 | focus_state_destroy(state); |
| 665 | } |
| 666 | |
| 667 | static void |
| 668 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 669 | { |
| 670 | struct focus_state *state = container_of(listener, |
| 671 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 672 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 673 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 674 | struct weston_surface *main_surface, *next; |
| 675 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 676 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 677 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 678 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 679 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 680 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 681 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 682 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 683 | if (is_focus_view(view)) |
| 684 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 685 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 686 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 687 | break; |
| 688 | } |
| 689 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 690 | /* if the focus was a sub-surface, activate its main surface */ |
| 691 | if (main_surface != state->keyboard_focus) |
| 692 | next = main_surface; |
| 693 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 694 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 695 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 696 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 697 | activate(shell, next, state->seat); |
| 698 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 699 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 700 | if (state->ws->focus_animation) |
| 701 | weston_view_animation_destroy(state->ws->focus_animation); |
| 702 | |
| 703 | state->ws->focus_animation = weston_fade_run( |
| 704 | state->ws->fsurf_front->view, |
| 705 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 706 | focus_animation_done, state->ws); |
| 707 | } |
| 708 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 709 | wl_list_remove(&state->link); |
| 710 | focus_state_destroy(state); |
| 711 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 715 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 716 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 717 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 718 | |
| 719 | state = malloc(sizeof *state); |
| 720 | if (state == NULL) |
| 721 | return NULL; |
| 722 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 723 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 724 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 725 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 726 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 727 | |
| 728 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 729 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 730 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 731 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 732 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 733 | |
| 734 | return state; |
| 735 | } |
| 736 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 737 | static struct focus_state * |
| 738 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 739 | { |
| 740 | struct workspace *ws = get_current_workspace(shell); |
| 741 | struct focus_state *state; |
| 742 | |
| 743 | wl_list_for_each(state, &ws->focus_list, link) |
| 744 | if (state->seat == seat) |
| 745 | break; |
| 746 | |
| 747 | if (&state->link == &ws->focus_list) |
| 748 | state = focus_state_create(seat, ws); |
| 749 | |
| 750 | return state; |
| 751 | } |
| 752 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 753 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 754 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 755 | { |
| 756 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 757 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 758 | |
| 759 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 760 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 761 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 762 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
| 766 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 767 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 768 | struct weston_seat *seat) |
| 769 | { |
| 770 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 771 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 772 | |
| 773 | wl_list_for_each(state, &ws->focus_list, link) { |
| 774 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 775 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 776 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 777 | return; |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | static void |
| 783 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 784 | struct weston_surface *surface) |
| 785 | { |
| 786 | struct focus_state *state; |
| 787 | |
| 788 | wl_list_for_each(state, &ws->focus_list, link) |
| 789 | if (state->keyboard_focus == surface) |
| 790 | state->keyboard_focus = NULL; |
| 791 | } |
| 792 | |
| 793 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 794 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 795 | struct weston_view *from, struct weston_view *to) |
| 796 | { |
| 797 | struct weston_output *output; |
| 798 | bool focus_surface_created = false; |
| 799 | |
| 800 | /* FIXME: Only support dim animation using two layers */ |
| 801 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 802 | return; |
| 803 | |
| 804 | output = get_default_output(shell->compositor); |
| 805 | if (ws->fsurf_front == NULL && (from || to)) { |
| 806 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 807 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 808 | ws->fsurf_front->view->alpha = 0.0; |
| 809 | ws->fsurf_back->view->alpha = 0.0; |
| 810 | focus_surface_created = true; |
| 811 | } else { |
| 812 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 813 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 814 | } |
| 815 | |
| 816 | if (ws->focus_animation) { |
| 817 | weston_view_animation_destroy(ws->focus_animation); |
| 818 | ws->focus_animation = NULL; |
| 819 | } |
| 820 | |
| 821 | if (to) |
| 822 | wl_list_insert(&to->layer_link, |
| 823 | &ws->fsurf_front->view->layer_link); |
| 824 | else if (from) |
| 825 | wl_list_insert(&ws->layer.view_list, |
| 826 | &ws->fsurf_front->view->layer_link); |
| 827 | |
| 828 | if (focus_surface_created) { |
| 829 | ws->focus_animation = weston_fade_run( |
| 830 | ws->fsurf_front->view, |
| 831 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 832 | focus_animation_done, ws); |
| 833 | } else if (from) { |
| 834 | wl_list_insert(&from->layer_link, |
| 835 | &ws->fsurf_back->view->layer_link); |
| 836 | ws->focus_animation = weston_stable_fade_run( |
| 837 | ws->fsurf_front->view, 0.0, |
| 838 | ws->fsurf_back->view, 0.6, |
| 839 | focus_animation_done, ws); |
| 840 | } else if (to) { |
| 841 | wl_list_insert(&ws->layer.view_list, |
| 842 | &ws->fsurf_back->view->layer_link); |
| 843 | ws->focus_animation = weston_stable_fade_run( |
| 844 | ws->fsurf_front->view, 0.0, |
| 845 | ws->fsurf_back->view, 0.6, |
| 846 | focus_animation_done, ws); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 851 | workspace_destroy(struct workspace *ws) |
| 852 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 853 | struct focus_state *state, *next; |
| 854 | |
| 855 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 856 | focus_state_destroy(state); |
| 857 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 858 | if (ws->fsurf_front) |
| 859 | focus_surface_destroy(ws->fsurf_front); |
| 860 | if (ws->fsurf_back) |
| 861 | focus_surface_destroy(ws->fsurf_back); |
| 862 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 863 | free(ws); |
| 864 | } |
| 865 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 866 | static void |
| 867 | seat_destroyed(struct wl_listener *listener, void *data) |
| 868 | { |
| 869 | struct weston_seat *seat = data; |
| 870 | struct focus_state *state, *next; |
| 871 | struct workspace *ws = container_of(listener, |
| 872 | struct workspace, |
| 873 | seat_destroyed_listener); |
| 874 | |
| 875 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 876 | if (state->seat == seat) |
| 877 | wl_list_remove(&state->link); |
| 878 | } |
| 879 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 880 | static struct workspace * |
| 881 | workspace_create(void) |
| 882 | { |
| 883 | struct workspace *ws = malloc(sizeof *ws); |
| 884 | if (ws == NULL) |
| 885 | return NULL; |
| 886 | |
| 887 | weston_layer_init(&ws->layer, NULL); |
| 888 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 889 | wl_list_init(&ws->focus_list); |
| 890 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 891 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 892 | ws->fsurf_front = NULL; |
| 893 | ws->fsurf_back = NULL; |
| 894 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 895 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 896 | return ws; |
| 897 | } |
| 898 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 899 | static int |
| 900 | workspace_is_empty(struct workspace *ws) |
| 901 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 902 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 903 | } |
| 904 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 905 | static struct workspace * |
| 906 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 907 | { |
| 908 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 909 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 910 | pws += index; |
| 911 | return *pws; |
| 912 | } |
| 913 | |
| 914 | static struct workspace * |
| 915 | get_current_workspace(struct desktop_shell *shell) |
| 916 | { |
| 917 | return get_workspace(shell, shell->workspaces.current); |
| 918 | } |
| 919 | |
| 920 | static void |
| 921 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 922 | { |
| 923 | struct workspace *ws; |
| 924 | |
| 925 | ws = get_workspace(shell, index); |
| 926 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 927 | |
| 928 | shell->workspaces.current = index; |
| 929 | } |
| 930 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 931 | static unsigned int |
| 932 | get_output_height(struct weston_output *output) |
| 933 | { |
| 934 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 935 | } |
| 936 | |
| 937 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 938 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 939 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 940 | struct weston_transform *transform; |
| 941 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 942 | if (is_focus_view(view)) { |
| 943 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 944 | transform = &fsurf->workspace_transform; |
| 945 | } else { |
| 946 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 947 | transform = &shsurf->workspace_transform; |
| 948 | } |
| 949 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 950 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 951 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 952 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 953 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 954 | weston_matrix_init(&transform->matrix); |
| 955 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 956 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 957 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | static void |
| 961 | workspace_translate_out(struct workspace *ws, double fraction) |
| 962 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 963 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 964 | unsigned int height; |
| 965 | double d; |
| 966 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 967 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 968 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 969 | d = height * fraction; |
| 970 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 971 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | |
| 975 | static void |
| 976 | workspace_translate_in(struct workspace *ws, double fraction) |
| 977 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 978 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 979 | unsigned int height; |
| 980 | double d; |
| 981 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 982 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 983 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 984 | |
| 985 | if (fraction > 0) |
| 986 | d = -(height - height * fraction); |
| 987 | else |
| 988 | d = height + height * fraction; |
| 989 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 990 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | |
| 994 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 995 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 996 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 997 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 998 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 999 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1000 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1001 | shell->workspaces.current, |
| 1002 | shell->workspaces.num); |
| 1003 | } |
| 1004 | |
| 1005 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1006 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1007 | unsigned int index, |
| 1008 | struct workspace *from, |
| 1009 | struct workspace *to) |
| 1010 | { |
| 1011 | shell->workspaces.current = index; |
| 1012 | |
| 1013 | shell->workspaces.anim_to = to; |
| 1014 | shell->workspaces.anim_from = from; |
| 1015 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1016 | shell->workspaces.anim_timestamp = 0; |
| 1017 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1018 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | static void |
| 1022 | workspace_deactivate_transforms(struct workspace *ws) |
| 1023 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1024 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1025 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1026 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1027 | 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] | 1028 | if (is_focus_view(view)) { |
| 1029 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1030 | transform = &fsurf->workspace_transform; |
| 1031 | } else { |
| 1032 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1033 | transform = &shsurf->workspace_transform; |
| 1034 | } |
| 1035 | |
| 1036 | if (!wl_list_empty(&transform->link)) { |
| 1037 | wl_list_remove(&transform->link); |
| 1038 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1039 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1040 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | static void |
| 1045 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1046 | struct workspace *from, |
| 1047 | struct workspace *to) |
| 1048 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1049 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1050 | |
| 1051 | wl_list_remove(&shell->workspaces.animation.link); |
| 1052 | workspace_deactivate_transforms(from); |
| 1053 | workspace_deactivate_transforms(to); |
| 1054 | shell->workspaces.anim_to = NULL; |
| 1055 | |
| 1056 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1057 | } |
| 1058 | |
| 1059 | static void |
| 1060 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1061 | struct weston_output *output, uint32_t msecs) |
| 1062 | { |
| 1063 | struct desktop_shell *shell = |
| 1064 | container_of(animation, struct desktop_shell, |
| 1065 | workspaces.animation); |
| 1066 | struct workspace *from = shell->workspaces.anim_from; |
| 1067 | struct workspace *to = shell->workspaces.anim_to; |
| 1068 | uint32_t t; |
| 1069 | double x, y; |
| 1070 | |
| 1071 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1072 | finish_workspace_change_animation(shell, from, to); |
| 1073 | return; |
| 1074 | } |
| 1075 | |
| 1076 | if (shell->workspaces.anim_timestamp == 0) { |
| 1077 | if (shell->workspaces.anim_current == 0.0) |
| 1078 | shell->workspaces.anim_timestamp = msecs; |
| 1079 | else |
| 1080 | shell->workspaces.anim_timestamp = |
| 1081 | msecs - |
| 1082 | /* Invers of movement function 'y' below. */ |
| 1083 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1084 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1085 | M_2_PI); |
| 1086 | } |
| 1087 | |
| 1088 | t = msecs - shell->workspaces.anim_timestamp; |
| 1089 | |
| 1090 | /* |
| 1091 | * x = [0, π/2] |
| 1092 | * y(x) = sin(x) |
| 1093 | */ |
| 1094 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1095 | y = sin(x); |
| 1096 | |
| 1097 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1098 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1099 | |
| 1100 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1101 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1102 | shell->workspaces.anim_current = y; |
| 1103 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1104 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1105 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1106 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1107 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | static void |
| 1111 | animate_workspace_change(struct desktop_shell *shell, |
| 1112 | unsigned int index, |
| 1113 | struct workspace *from, |
| 1114 | struct workspace *to) |
| 1115 | { |
| 1116 | struct weston_output *output; |
| 1117 | |
| 1118 | int dir; |
| 1119 | |
| 1120 | if (index > shell->workspaces.current) |
| 1121 | dir = -1; |
| 1122 | else |
| 1123 | dir = 1; |
| 1124 | |
| 1125 | shell->workspaces.current = index; |
| 1126 | |
| 1127 | shell->workspaces.anim_dir = dir; |
| 1128 | shell->workspaces.anim_from = from; |
| 1129 | shell->workspaces.anim_to = to; |
| 1130 | shell->workspaces.anim_current = 0.0; |
| 1131 | shell->workspaces.anim_timestamp = 0; |
| 1132 | |
| 1133 | output = container_of(shell->compositor->output_list.next, |
| 1134 | struct weston_output, link); |
| 1135 | wl_list_insert(&output->animation_list, |
| 1136 | &shell->workspaces.animation.link); |
| 1137 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1138 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1139 | |
| 1140 | workspace_translate_in(to, 0); |
| 1141 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1142 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1143 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1144 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1145 | } |
| 1146 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1147 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1148 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1149 | struct workspace *from, struct workspace *to) |
| 1150 | { |
| 1151 | shell->workspaces.current = index; |
| 1152 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1153 | wl_list_remove(&from->layer.link); |
| 1154 | } |
| 1155 | |
| 1156 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1157 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1158 | { |
| 1159 | struct workspace *from; |
| 1160 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1161 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1162 | |
| 1163 | if (index == shell->workspaces.current) |
| 1164 | return; |
| 1165 | |
| 1166 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1167 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1168 | return; |
| 1169 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1170 | from = get_current_workspace(shell); |
| 1171 | to = get_workspace(shell, index); |
| 1172 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1173 | if (shell->workspaces.anim_from == to && |
| 1174 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1175 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1176 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1177 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1178 | return; |
| 1179 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1180 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1181 | if (shell->workspaces.anim_to != NULL) |
| 1182 | finish_workspace_change_animation(shell, |
| 1183 | shell->workspaces.anim_from, |
| 1184 | shell->workspaces.anim_to); |
| 1185 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1186 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1187 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1188 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1189 | wl_list_for_each(state, &from->focus_list, link) |
| 1190 | if (state->keyboard_focus) |
| 1191 | animate_focus_change(shell, from, |
| 1192 | get_default_view(state->keyboard_focus), NULL); |
| 1193 | |
| 1194 | wl_list_for_each(state, &to->focus_list, link) |
| 1195 | if (state->keyboard_focus) |
| 1196 | animate_focus_change(shell, to, |
| 1197 | NULL, get_default_view(state->keyboard_focus)); |
| 1198 | } |
| 1199 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1200 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1201 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1202 | else |
| 1203 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1204 | |
| 1205 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1206 | } |
| 1207 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1208 | static bool |
| 1209 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1210 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1211 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1212 | struct wl_list *e; |
| 1213 | |
| 1214 | if (wl_list_empty(list)) |
| 1215 | return false; |
| 1216 | |
| 1217 | e = list->next; |
| 1218 | |
| 1219 | if (e->next != list) |
| 1220 | return false; |
| 1221 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1222 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1226 | move_view_to_workspace(struct desktop_shell *shell, |
| 1227 | struct weston_view *view, |
| 1228 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1229 | { |
| 1230 | struct workspace *from; |
| 1231 | struct workspace *to; |
| 1232 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1233 | struct weston_surface *focus; |
| 1234 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1235 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1236 | |
| 1237 | if (workspace == shell->workspaces.current) |
| 1238 | return; |
| 1239 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1240 | if (workspace >= shell->workspaces.num) |
| 1241 | workspace = shell->workspaces.num - 1; |
| 1242 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1243 | from = get_current_workspace(shell); |
| 1244 | to = get_workspace(shell, workspace); |
| 1245 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1246 | wl_list_remove(&view->layer_link); |
| 1247 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1248 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1249 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1250 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1251 | if (!seat->keyboard) |
| 1252 | continue; |
| 1253 | |
| 1254 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1255 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1256 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1257 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1258 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1259 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1263 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1264 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1265 | unsigned int index) |
| 1266 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1267 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1268 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1269 | struct shell_surface *shsurf; |
| 1270 | struct workspace *from; |
| 1271 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1272 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1273 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1274 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1275 | view = get_default_view(surface); |
| 1276 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1277 | index == shell->workspaces.current || |
| 1278 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1279 | return; |
| 1280 | |
| 1281 | from = get_current_workspace(shell); |
| 1282 | to = get_workspace(shell, index); |
| 1283 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1284 | wl_list_remove(&view->layer_link); |
| 1285 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1286 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1287 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1288 | drop_focus_state(shell, from, surface); |
| 1289 | |
| 1290 | if (shell->workspaces.anim_from == to && |
| 1291 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1292 | wl_list_remove(&to->layer.link); |
| 1293 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1294 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1295 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1296 | broadcast_current_workspace_state(shell); |
| 1297 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1298 | return; |
| 1299 | } |
| 1300 | |
| 1301 | if (shell->workspaces.anim_to != NULL) |
| 1302 | finish_workspace_change_animation(shell, |
| 1303 | shell->workspaces.anim_from, |
| 1304 | shell->workspaces.anim_to); |
| 1305 | |
| 1306 | if (workspace_is_empty(from) && |
| 1307 | workspace_has_only(to, surface)) |
| 1308 | update_workspace(shell, index, from, to); |
| 1309 | else { |
| 1310 | shsurf = get_shell_surface(surface); |
| 1311 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 1312 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1313 | &shsurf->workspace_transform.link); |
| 1314 | |
| 1315 | animate_workspace_change(shell, index, from, to); |
| 1316 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1317 | |
| 1318 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1319 | |
| 1320 | state = ensure_focus_state(shell, seat); |
| 1321 | if (state != NULL) |
| 1322 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | static void |
| 1326 | workspace_manager_move_surface(struct wl_client *client, |
| 1327 | struct wl_resource *resource, |
| 1328 | struct wl_resource *surface_resource, |
| 1329 | uint32_t workspace) |
| 1330 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1331 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1332 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1333 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1334 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1335 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1336 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1337 | main_surface = weston_surface_get_main_surface(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1338 | view = get_default_view(main_surface); |
| 1339 | if (!view) |
| 1340 | return; |
| 1341 | move_view_to_workspace(shell, view, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1345 | workspace_manager_move_surface, |
| 1346 | }; |
| 1347 | |
| 1348 | static void |
| 1349 | unbind_resource(struct wl_resource *resource) |
| 1350 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1351 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | static void |
| 1355 | bind_workspace_manager(struct wl_client *client, |
| 1356 | void *data, uint32_t version, uint32_t id) |
| 1357 | { |
| 1358 | struct desktop_shell *shell = data; |
| 1359 | struct wl_resource *resource; |
| 1360 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1361 | resource = wl_resource_create(client, |
| 1362 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1363 | |
| 1364 | if (resource == NULL) { |
| 1365 | weston_log("couldn't add workspace manager object"); |
| 1366 | return; |
| 1367 | } |
| 1368 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1369 | wl_resource_set_implementation(resource, |
| 1370 | &workspace_manager_implementation, |
| 1371 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1372 | wl_list_insert(&shell->workspaces.client_list, |
| 1373 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1374 | |
| 1375 | workspace_manager_send_state(resource, |
| 1376 | shell->workspaces.current, |
| 1377 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1378 | } |
| 1379 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1380 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1381 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1382 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1383 | { |
| 1384 | } |
| 1385 | |
| 1386 | static void |
| 1387 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1388 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1389 | struct weston_touch_move_grab *move = |
| 1390 | (struct weston_touch_move_grab *) container_of( |
| 1391 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1392 | |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1393 | if (grab->touch->seat->num_tp == 0) { |
| 1394 | shell_touch_grab_end(&move->base); |
| 1395 | free(move); |
| 1396 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | static void |
| 1400 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1401 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1402 | { |
| 1403 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1404 | struct shell_surface *shsurf = move->base.shsurf; |
| 1405 | struct weston_surface *es; |
| 1406 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1407 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1408 | |
| 1409 | if (!shsurf) |
| 1410 | return; |
| 1411 | |
| 1412 | es = shsurf->surface; |
| 1413 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1414 | weston_view_configure(shsurf->view, dx, dy, |
| 1415 | shsurf->view->geometry.width, |
| 1416 | shsurf->view->geometry.height); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1417 | |
| 1418 | weston_compositor_schedule_repaint(es->compositor); |
| 1419 | } |
| 1420 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1421 | static void |
| 1422 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1423 | { |
| 1424 | struct weston_touch_move_grab *move = |
| 1425 | (struct weston_touch_move_grab *) container_of( |
| 1426 | grab, struct shell_touch_grab, grab); |
| 1427 | |
| 1428 | shell_touch_grab_end(&move->base); |
| 1429 | free(move); |
| 1430 | } |
| 1431 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1432 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1433 | touch_move_grab_down, |
| 1434 | touch_move_grab_up, |
| 1435 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1436 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1437 | }; |
| 1438 | |
| 1439 | static int |
| 1440 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1441 | { |
| 1442 | struct weston_touch_move_grab *move; |
| 1443 | |
| 1444 | if (!shsurf) |
| 1445 | return -1; |
| 1446 | |
| 1447 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1448 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1449 | if (shsurf->grabbed) |
| 1450 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1451 | |
| 1452 | move = malloc(sizeof *move); |
| 1453 | if (!move) |
| 1454 | return -1; |
| 1455 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1456 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1457 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1458 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1459 | seat->touch->grab_y; |
| 1460 | |
| 1461 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1462 | seat->touch); |
| 1463 | |
| 1464 | return 0; |
| 1465 | } |
| 1466 | |
| 1467 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1468 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1469 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1473 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1474 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1475 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1476 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1477 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1478 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1479 | int dx, dy; |
| 1480 | |
| 1481 | weston_pointer_move(pointer, x, y); |
| 1482 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1483 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1484 | |
| 1485 | if (!shsurf) |
| 1486 | return; |
| 1487 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1488 | weston_view_configure(shsurf->view, dx, dy, |
| 1489 | shsurf->view->geometry.width, |
| 1490 | shsurf->view->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1491 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1492 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1496 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1497 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1498 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1499 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1500 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1501 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1502 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1503 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1504 | if (pointer->button_count == 0 && |
| 1505 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1506 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1507 | free(grab); |
| 1508 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1509 | } |
| 1510 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1511 | static void |
| 1512 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1513 | { |
| 1514 | struct shell_grab *shell_grab = |
| 1515 | container_of(grab, struct shell_grab, grab); |
| 1516 | |
| 1517 | shell_grab_end(shell_grab); |
| 1518 | free(grab); |
| 1519 | } |
| 1520 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1521 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1522 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1523 | move_grab_motion, |
| 1524 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1525 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1526 | }; |
| 1527 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1528 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1529 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1530 | { |
| 1531 | struct weston_move_grab *move; |
| 1532 | |
| 1533 | if (!shsurf) |
| 1534 | return -1; |
| 1535 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1536 | if (shsurf->grabbed) |
| 1537 | return 0; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1538 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1539 | return 0; |
| 1540 | |
| 1541 | move = malloc(sizeof *move); |
| 1542 | if (!move) |
| 1543 | return -1; |
| 1544 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1545 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1546 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1547 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1548 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1549 | |
| 1550 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1551 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1552 | |
| 1553 | return 0; |
| 1554 | } |
| 1555 | |
| 1556 | static void |
| 1557 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1558 | struct wl_resource *seat_resource, uint32_t serial) |
| 1559 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1560 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1561 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1562 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1563 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1564 | if (seat->pointer && |
| 1565 | seat->pointer->button_count > 0 && |
| 1566 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1567 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1568 | if ((surface == shsurf->surface) && |
| 1569 | (surface_move(shsurf, seat) < 0)) |
| 1570 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1571 | } else if (seat->touch && |
| 1572 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1573 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1574 | if ((surface == shsurf->surface) && |
| 1575 | (surface_touch_move(shsurf, seat) < 0)) |
| 1576 | wl_resource_post_no_memory(resource); |
| 1577 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | struct weston_resize_grab { |
| 1581 | struct shell_grab base; |
| 1582 | uint32_t edges; |
| 1583 | int32_t width, height; |
| 1584 | }; |
| 1585 | |
| 1586 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1587 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1588 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1589 | { |
| 1590 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1591 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1592 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1593 | int32_t width, height; |
| 1594 | wl_fixed_t from_x, from_y; |
| 1595 | wl_fixed_t to_x, to_y; |
| 1596 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1597 | weston_pointer_move(pointer, x, y); |
| 1598 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1599 | if (!shsurf) |
| 1600 | return; |
| 1601 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1602 | weston_view_from_global_fixed(shsurf->view, |
| 1603 | pointer->grab_x, pointer->grab_y, |
| 1604 | &from_x, &from_y); |
| 1605 | weston_view_from_global_fixed(shsurf->view, |
| 1606 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1607 | |
| 1608 | width = resize->width; |
| 1609 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1610 | width += wl_fixed_to_int(from_x - to_x); |
| 1611 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1612 | width += wl_fixed_to_int(to_x - from_x); |
| 1613 | } |
| 1614 | |
| 1615 | height = resize->height; |
| 1616 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1617 | height += wl_fixed_to_int(from_y - to_y); |
| 1618 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1619 | height += wl_fixed_to_int(to_y - from_y); |
| 1620 | } |
| 1621 | |
| 1622 | shsurf->client->send_configure(shsurf->surface, |
| 1623 | resize->edges, width, height); |
| 1624 | } |
| 1625 | |
| 1626 | static void |
| 1627 | send_configure(struct weston_surface *surface, |
| 1628 | uint32_t edges, int32_t width, int32_t height) |
| 1629 | { |
| 1630 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1631 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1632 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1633 | edges, width, height); |
| 1634 | } |
| 1635 | |
| 1636 | static const struct weston_shell_client shell_client = { |
| 1637 | send_configure |
| 1638 | }; |
| 1639 | |
| 1640 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1641 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1642 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1643 | { |
| 1644 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1645 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1646 | enum wl_pointer_button_state state = state_w; |
| 1647 | |
| 1648 | if (pointer->button_count == 0 && |
| 1649 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1650 | shell_grab_end(&resize->base); |
| 1651 | free(grab); |
| 1652 | } |
| 1653 | } |
| 1654 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1655 | static void |
| 1656 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1657 | { |
| 1658 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1659 | |
| 1660 | shell_grab_end(&resize->base); |
| 1661 | free(grab); |
| 1662 | } |
| 1663 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1664 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1665 | noop_grab_focus, |
| 1666 | resize_grab_motion, |
| 1667 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1668 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1669 | }; |
| 1670 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1671 | /* |
| 1672 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1673 | * in the surface coordinates system. */ |
| 1674 | static void |
| 1675 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1676 | int32_t *y, int32_t *w, int32_t *h) { |
| 1677 | pixman_region32_t region; |
| 1678 | pixman_box32_t *box; |
| 1679 | struct weston_subsurface *subsurface; |
| 1680 | |
| 1681 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1682 | surface->width, |
| 1683 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1684 | |
| 1685 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1686 | pixman_region32_union_rect(®ion, ®ion, |
| 1687 | subsurface->position.x, |
| 1688 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1689 | subsurface->surface->width, |
| 1690 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | box = pixman_region32_extents(®ion); |
| 1694 | if (x) |
| 1695 | *x = box->x1; |
| 1696 | if (y) |
| 1697 | *y = box->y1; |
| 1698 | if (w) |
| 1699 | *w = box->x2 - box->x1; |
| 1700 | if (h) |
| 1701 | *h = box->y2 - box->y1; |
| 1702 | |
| 1703 | pixman_region32_fini(®ion); |
| 1704 | } |
| 1705 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1706 | static int |
| 1707 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1708 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1709 | { |
| 1710 | struct weston_resize_grab *resize; |
| 1711 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1712 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1713 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1714 | return 0; |
| 1715 | |
| 1716 | if (edges == 0 || edges > 15 || |
| 1717 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1718 | return 0; |
| 1719 | |
| 1720 | resize = malloc(sizeof *resize); |
| 1721 | if (!resize) |
| 1722 | return -1; |
| 1723 | |
| 1724 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1725 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1726 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1727 | |
| 1728 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1729 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1730 | |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |
| 1734 | static void |
| 1735 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1736 | struct wl_resource *seat_resource, uint32_t serial, |
| 1737 | uint32_t edges) |
| 1738 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1739 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1740 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1741 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1742 | |
| 1743 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1744 | return; |
| 1745 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1746 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1747 | if (seat->pointer->button_count == 0 || |
| 1748 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1749 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1750 | return; |
| 1751 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1752 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1753 | wl_resource_post_no_memory(resource); |
| 1754 | } |
| 1755 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1756 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1757 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1758 | |
| 1759 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1760 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1761 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1762 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1763 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1764 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1765 | wl_fixed_t sx, sy; |
| 1766 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1767 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1768 | pointer->x, pointer->y, |
| 1769 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1770 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1771 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1772 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1776 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1777 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1778 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1779 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1780 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1781 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1782 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1783 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1784 | uint32_t time, uint32_t button, uint32_t state) |
| 1785 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1786 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1787 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1788 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1789 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1790 | if (shsurf && button == BTN_LEFT && state) { |
| 1791 | activate(shsurf->shell, shsurf->surface, seat); |
| 1792 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1793 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1794 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1795 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1796 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1797 | } |
| 1798 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1799 | static void |
| 1800 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1801 | { |
| 1802 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1803 | |
| 1804 | shell_grab_end(grab); |
| 1805 | free(grab); |
| 1806 | } |
| 1807 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1808 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1809 | busy_cursor_grab_focus, |
| 1810 | busy_cursor_grab_motion, |
| 1811 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1812 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1813 | }; |
| 1814 | |
| 1815 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1816 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1817 | { |
| 1818 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1819 | |
| 1820 | grab = malloc(sizeof *grab); |
| 1821 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1822 | return; |
| 1823 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1824 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1825 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1826 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1827 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1828 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1829 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1830 | { |
| 1831 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1832 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1833 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1834 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1835 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1836 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1837 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1838 | } |
| 1839 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1840 | static void |
| 1841 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1842 | { |
| 1843 | if (!shsurf || !shsurf->ping_timer) |
| 1844 | return; |
| 1845 | |
| 1846 | if (shsurf->ping_timer->source) |
| 1847 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1848 | |
| 1849 | free(shsurf->ping_timer); |
| 1850 | shsurf->ping_timer = NULL; |
| 1851 | } |
| 1852 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1853 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1854 | ping_timeout_handler(void *data) |
| 1855 | { |
| 1856 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1857 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1858 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1859 | /* Client is not responding */ |
| 1860 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1861 | |
| 1862 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1863 | if (seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1864 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1865 | |
| 1866 | return 1; |
| 1867 | } |
| 1868 | |
| 1869 | static void |
| 1870 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1871 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1872 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1873 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1874 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1875 | |
| 1876 | if (!shsurf) |
| 1877 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1878 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1879 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1880 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1881 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1882 | return; |
| 1883 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1884 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1885 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1886 | if (!shsurf->ping_timer) |
| 1887 | return; |
| 1888 | |
| 1889 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1890 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1891 | shsurf->ping_timer->source = |
| 1892 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1893 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1894 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1895 | wl_shell_surface_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1900 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1901 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1902 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1903 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1904 | struct weston_compositor *compositor; |
| 1905 | struct shell_surface *shsurf; |
| 1906 | uint32_t serial; |
| 1907 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1908 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1909 | return; |
| 1910 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1911 | compositor = view->surface->compositor; |
| 1912 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1913 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1914 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1915 | set_busy_cursor(shsurf, pointer); |
| 1916 | } else { |
| 1917 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1918 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1923 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1924 | { |
| 1925 | struct wl_listener *listener; |
| 1926 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1927 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1928 | return; |
| 1929 | |
| 1930 | listener = malloc(sizeof *listener); |
| 1931 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1932 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1936 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1937 | uint32_t serial) |
| 1938 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1939 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1940 | struct weston_seat *seat; |
| 1941 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1942 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1943 | if (shsurf->ping_timer == NULL) |
| 1944 | /* Just ignore unsolicited pong. */ |
| 1945 | return; |
| 1946 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1947 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1948 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1949 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1950 | if(seat->pointer) |
| 1951 | end_busy_cursor(shsurf, seat->pointer); |
| 1952 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1953 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1957 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1958 | set_title(struct shell_surface *shsurf, const char *title) |
| 1959 | { |
| 1960 | free(shsurf->title); |
| 1961 | shsurf->title = strdup(title); |
| 1962 | } |
| 1963 | |
| 1964 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1965 | shell_surface_set_title(struct wl_client *client, |
| 1966 | struct wl_resource *resource, const char *title) |
| 1967 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1968 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1969 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 1970 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | static void |
| 1974 | shell_surface_set_class(struct wl_client *client, |
| 1975 | struct wl_resource *resource, const char *class) |
| 1976 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1977 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1978 | |
| 1979 | free(shsurf->class); |
| 1980 | shsurf->class = strdup(class); |
| 1981 | } |
| 1982 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1983 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1984 | restore_output_mode(struct weston_output *output) |
| 1985 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1986 | if (output->current_mode != output->original_mode || |
| 1987 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1988 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 1989 | output->original_mode, |
| 1990 | output->original_scale, |
| 1991 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | static void |
| 1995 | restore_all_output_modes(struct weston_compositor *compositor) |
| 1996 | { |
| 1997 | struct weston_output *output; |
| 1998 | |
| 1999 | wl_list_for_each(output, &compositor->output_list, link) |
| 2000 | restore_output_mode(output); |
| 2001 | } |
| 2002 | |
| 2003 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2004 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 2005 | { |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2006 | struct workspace *ws; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2007 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2008 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2009 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2010 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2011 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2012 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2013 | shsurf->fullscreen.framerate = 0; |
| 2014 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2015 | wl_list_init(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2016 | if (shsurf->fullscreen.black_view) |
| 2017 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2018 | shsurf->fullscreen.black_view = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2019 | shsurf->fullscreen_output = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2020 | weston_view_set_position(shsurf->view, |
| 2021 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2022 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2023 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2024 | &shsurf->rotation.transform.link); |
| 2025 | shsurf->saved_rotation_valid = false; |
| 2026 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2027 | |
| 2028 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2029 | wl_list_remove(&shsurf->view->layer_link); |
| 2030 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2031 | } |
| 2032 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2033 | static void |
| 2034 | shell_unset_maximized(struct shell_surface *shsurf) |
| 2035 | { |
| 2036 | struct workspace *ws; |
| 2037 | /* undo all maximized things here */ |
| 2038 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2039 | weston_view_set_position(shsurf->view, |
| 2040 | shsurf->saved_x, |
| 2041 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2042 | |
| 2043 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2044 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2045 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2046 | shsurf->saved_rotation_valid = false; |
| 2047 | } |
| 2048 | |
| 2049 | ws = get_current_workspace(shsurf->shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2050 | wl_list_remove(&shsurf->view->layer_link); |
| 2051 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2052 | } |
| 2053 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2054 | static int |
| 2055 | reset_shell_surface_type(struct shell_surface *surface) |
| 2056 | { |
| 2057 | switch (surface->type) { |
| 2058 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2059 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2060 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2061 | case SHELL_SURFACE_MAXIMIZED: |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2062 | shell_unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2063 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2064 | case SHELL_SURFACE_NONE: |
| 2065 | case SHELL_SURFACE_TOPLEVEL: |
| 2066 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2067 | case SHELL_SURFACE_POPUP: |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2068 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2069 | break; |
| 2070 | } |
| 2071 | |
| 2072 | surface->type = SHELL_SURFACE_NONE; |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2076 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2077 | set_surface_type(struct shell_surface *shsurf) |
| 2078 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2079 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2080 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2081 | |
| 2082 | reset_shell_surface_type(shsurf); |
| 2083 | |
| 2084 | shsurf->type = shsurf->next_type; |
| 2085 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 2086 | |
| 2087 | switch (shsurf->type) { |
| 2088 | case SHELL_SURFACE_TOPLEVEL: |
| 2089 | break; |
| 2090 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2091 | if (pev) |
| 2092 | weston_view_set_position(shsurf->view, |
| 2093 | pev->geometry.x + shsurf->transient.x, |
| 2094 | pev->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2095 | break; |
| 2096 | |
| 2097 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2098 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2099 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2100 | shsurf->saved_y = shsurf->view->geometry.y; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2101 | shsurf->saved_position_valid = true; |
| 2102 | |
| 2103 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2104 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2105 | wl_list_init(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2106 | weston_view_geometry_dirty(shsurf->view); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2107 | shsurf->saved_rotation_valid = true; |
| 2108 | } |
| 2109 | break; |
| 2110 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2111 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2112 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2113 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2114 | break; |
| 2115 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2116 | default: |
| 2117 | break; |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2122 | set_toplevel(struct shell_surface *shsurf) |
| 2123 | { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2124 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2128 | shell_surface_set_toplevel(struct wl_client *client, |
| 2129 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2130 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2131 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2132 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2133 | set_toplevel(surface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | static void |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2137 | set_transient(struct shell_surface *shsurf, |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2138 | struct weston_surface *parent, int x, int y, uint32_t flags) |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2139 | { |
| 2140 | /* assign to parents output */ |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2141 | shsurf->parent = parent; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 2142 | shsurf->transient.x = x; |
| 2143 | shsurf->transient.y = y; |
| 2144 | shsurf->transient.flags = flags; |
| 2145 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 2146 | } |
| 2147 | |
| 2148 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2149 | shell_surface_set_transient(struct wl_client *client, |
| 2150 | struct wl_resource *resource, |
| 2151 | struct wl_resource *parent_resource, |
| 2152 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2153 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2154 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2155 | struct weston_surface *parent = |
| 2156 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2157 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2158 | set_transient(shsurf, parent, x, y, flags); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2159 | } |
| 2160 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2161 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2162 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2163 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2164 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2168 | get_output_panel_height(struct desktop_shell *shell, |
| 2169 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2170 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2171 | struct weston_view *view; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2172 | int panel_height = 0; |
| 2173 | |
| 2174 | if (!output) |
| 2175 | return 0; |
| 2176 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2177 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2178 | if (view->surface->output == output) { |
| 2179 | panel_height = view->geometry.height; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2180 | break; |
| 2181 | } |
| 2182 | } |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2183 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2184 | return panel_height; |
| 2185 | } |
| 2186 | |
| 2187 | static void |
| 2188 | shell_surface_set_maximized(struct wl_client *client, |
| 2189 | struct wl_resource *resource, |
| 2190 | struct wl_resource *output_resource ) |
| 2191 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2192 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2193 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2194 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2195 | uint32_t edges = 0, panel_height = 0; |
| 2196 | |
| 2197 | /* get the default output, if the client set it as NULL |
| 2198 | check whether the ouput is available */ |
| 2199 | if (output_resource) |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2200 | shsurf->output = wl_resource_get_user_data(output_resource); |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 2201 | else if (es->output) |
| 2202 | shsurf->output = es->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2203 | else |
| 2204 | shsurf->output = get_default_output(es->compositor); |
| 2205 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2206 | shell = shell_surface_get_shell(shsurf); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 2207 | panel_height = get_output_panel_height(shell, shsurf->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2208 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2209 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2210 | shsurf->client->send_configure(shsurf->surface, edges, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2211 | shsurf->output->width, |
| 2212 | shsurf->output->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2213 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2214 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2215 | } |
| 2216 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2217 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2218 | 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] | 2219 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2220 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2221 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2222 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2223 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2224 | { |
| 2225 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2226 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2227 | |
| 2228 | surface = weston_surface_create(ec); |
| 2229 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2230 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2231 | return NULL; |
| 2232 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2233 | view = weston_view_create(surface); |
| 2234 | if (surface == NULL) { |
| 2235 | weston_log("no memory\n"); |
| 2236 | weston_surface_destroy(surface); |
| 2237 | return NULL; |
| 2238 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2239 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2240 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2241 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2242 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2243 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2244 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2245 | pixman_region32_fini(&surface->input); |
| 2246 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2247 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2248 | weston_view_configure(view, x, y, w, h); |
| 2249 | |
| 2250 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | /* Create black surface and append it to the associated fullscreen surface. |
| 2254 | * Handle size dismatch and positioning according to the method. */ |
| 2255 | static void |
| 2256 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2257 | { |
| 2258 | struct weston_output *output = shsurf->fullscreen_output; |
| 2259 | struct weston_surface *surface = shsurf->surface; |
| 2260 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2261 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2262 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2263 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2264 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2265 | restore_output_mode(output); |
| 2266 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2267 | if (!shsurf->fullscreen.black_view) |
| 2268 | shsurf->fullscreen.black_view = |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2269 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2270 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2271 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2272 | output->width, |
| 2273 | output->height); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2274 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2275 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2276 | wl_list_insert(&shsurf->view->layer_link, |
| 2277 | &shsurf->fullscreen.black_view->layer_link); |
| 2278 | shsurf->fullscreen.black_view->surface->output = output; |
| 2279 | shsurf->fullscreen.black_view->output = output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2280 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2281 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2282 | &surf_width, &surf_height); |
| 2283 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2284 | switch (shsurf->fullscreen.type) { |
| 2285 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2286 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2287 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2288 | break; |
| 2289 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2290 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2291 | if (output->width == surf_width && |
| 2292 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2293 | weston_view_set_position(shsurf->view, |
| 2294 | output->x - surf_x, |
| 2295 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2296 | break; |
| 2297 | } |
| 2298 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2299 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2300 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2301 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2302 | output_aspect = (float) output->width / |
| 2303 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2304 | /* XXX: Use surf_width and surf_height here? */ |
| 2305 | surface_aspect = (float) surface->width / |
| 2306 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2307 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2308 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2309 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2310 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2311 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2312 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2313 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2314 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2315 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2316 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2317 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2318 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2319 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2320 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2321 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2322 | break; |
| 2323 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2324 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2325 | struct weston_mode mode = {0, |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 2326 | surf_width * surface->buffer_scale, |
| 2327 | surf_height * surface->buffer_scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2328 | shsurf->fullscreen.framerate}; |
| 2329 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2330 | if (weston_output_switch_mode(output, &mode, surface->buffer_scale, |
| 2331 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2332 | weston_view_set_position(shsurf->view, |
| 2333 | output->x - surf_x, |
| 2334 | output->y - surf_y); |
| 2335 | weston_view_configure(shsurf->fullscreen.black_view, |
| 2336 | output->x - surf_x, |
| 2337 | output->y - surf_y, |
| 2338 | output->width, |
| 2339 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2340 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2341 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2342 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2343 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2344 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2345 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2346 | break; |
| 2347 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2348 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2349 | break; |
| 2350 | default: |
| 2351 | break; |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | /* make the fullscreen and black surface at the top */ |
| 2356 | static void |
| 2357 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 2358 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2359 | struct weston_output *output = shsurf->fullscreen_output; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2360 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2361 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2362 | wl_list_remove(&shsurf->view->layer_link); |
| 2363 | wl_list_insert(&shell->fullscreen_layer.view_list, |
| 2364 | &shsurf->view->layer_link); |
| 2365 | weston_surface_damage(shsurf->surface); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2366 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2367 | if (!shsurf->fullscreen.black_view) |
| 2368 | shsurf->fullscreen.black_view = |
| 2369 | create_black_surface(shsurf->surface->compositor, |
| 2370 | shsurf->surface, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2371 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2372 | output->width, |
| 2373 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2374 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2375 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2376 | wl_list_insert(&shsurf->view->layer_link, |
| 2377 | &shsurf->fullscreen.black_view->layer_link); |
| 2378 | weston_surface_damage(shsurf->fullscreen.black_view->surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | static void |
| 2382 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2383 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2384 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2385 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2386 | } |
| 2387 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2388 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2389 | set_fullscreen(struct shell_surface *shsurf, |
| 2390 | uint32_t method, |
| 2391 | uint32_t framerate, |
| 2392 | struct weston_output *output) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2393 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2394 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2395 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2396 | if (output) |
| 2397 | shsurf->output = output; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 2398 | else if (es->output) |
| 2399 | shsurf->output = es->output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2400 | else |
| 2401 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2402 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2403 | shsurf->fullscreen_output = shsurf->output; |
| 2404 | shsurf->fullscreen.type = method; |
| 2405 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2406 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2407 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2408 | shsurf->client->send_configure(shsurf->surface, 0, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2409 | shsurf->output->width, |
| 2410 | shsurf->output->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2411 | } |
| 2412 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2413 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2414 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2415 | struct wl_resource *resource, |
| 2416 | uint32_t method, |
| 2417 | uint32_t framerate, |
| 2418 | struct wl_resource *output_resource) |
| 2419 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2420 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2421 | struct weston_output *output; |
| 2422 | |
| 2423 | if (output_resource) |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2424 | output = wl_resource_get_user_data(output_resource); |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2425 | else |
| 2426 | output = NULL; |
| 2427 | |
| 2428 | set_fullscreen(shsurf, method, framerate, output); |
| 2429 | } |
| 2430 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2431 | static void |
| 2432 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2433 | { |
| 2434 | /* XXX: using the same fields for transient type */ |
| 2435 | shsurf->transient.x = x; |
| 2436 | shsurf->transient.y = y; |
| 2437 | shsurf->transient.flags = flags; |
| 2438 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2439 | } |
| 2440 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2441 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2442 | |
| 2443 | static void |
| 2444 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2445 | { |
| 2446 | struct shell_seat *shseat = |
| 2447 | container_of(listener, |
| 2448 | struct shell_seat, seat_destroy_listener); |
| 2449 | struct shell_surface *shsurf, *prev = NULL; |
| 2450 | |
| 2451 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2452 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2453 | shseat->popup_grab.client = NULL; |
| 2454 | |
| 2455 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2456 | shsurf->popup.shseat = NULL; |
| 2457 | if (prev) { |
| 2458 | wl_list_init(&prev->popup.grab_link); |
| 2459 | } |
| 2460 | prev = shsurf; |
| 2461 | } |
| 2462 | wl_list_init(&prev->popup.grab_link); |
| 2463 | } |
| 2464 | |
| 2465 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2466 | free(shseat); |
| 2467 | } |
| 2468 | |
| 2469 | static struct shell_seat * |
| 2470 | create_shell_seat(struct weston_seat *seat) |
| 2471 | { |
| 2472 | struct shell_seat *shseat; |
| 2473 | |
| 2474 | shseat = calloc(1, sizeof *shseat); |
| 2475 | if (!shseat) { |
| 2476 | weston_log("no memory to allocate shell seat\n"); |
| 2477 | return NULL; |
| 2478 | } |
| 2479 | |
| 2480 | shseat->seat = seat; |
| 2481 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2482 | |
| 2483 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2484 | wl_signal_add(&seat->destroy_signal, |
| 2485 | &shseat->seat_destroy_listener); |
| 2486 | |
| 2487 | return shseat; |
| 2488 | } |
| 2489 | |
| 2490 | static struct shell_seat * |
| 2491 | get_shell_seat(struct weston_seat *seat) |
| 2492 | { |
| 2493 | struct wl_listener *listener; |
| 2494 | |
| 2495 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2496 | if (listener == NULL) |
| 2497 | return create_shell_seat(seat); |
| 2498 | |
| 2499 | return container_of(listener, |
| 2500 | struct shell_seat, seat_destroy_listener); |
| 2501 | } |
| 2502 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2503 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2504 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2505 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2506 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2507 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2508 | struct shell_seat *shseat = |
| 2509 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2510 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2511 | wl_fixed_t sx, sy; |
| 2512 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2513 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2514 | pointer->x, pointer->y, |
| 2515 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2516 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2517 | if (view && view->surface->resource && |
| 2518 | wl_resource_get_client(view->surface->resource) == client) { |
| 2519 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2520 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2521 | weston_pointer_set_focus(pointer, NULL, |
| 2522 | wl_fixed_from_int(0), |
| 2523 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2524 | } |
| 2525 | } |
| 2526 | |
| 2527 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2528 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2529 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2530 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2531 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2532 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2533 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2534 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2535 | weston_pointer_move(pointer, x, y); |
| 2536 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2537 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2538 | weston_view_from_global_fixed(pointer->focus, |
| 2539 | pointer->x, pointer->y, |
| 2540 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2541 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2542 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2546 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2547 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2548 | { |
| 2549 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2550 | struct shell_seat *shseat = |
| 2551 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2552 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2553 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2554 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2555 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2556 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2557 | resource_list = &grab->pointer->focus_resource_list; |
| 2558 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2559 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2560 | wl_resource_for_each(resource, resource_list) { |
| 2561 | wl_pointer_send_button(resource, serial, |
| 2562 | time, button, state); |
| 2563 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2564 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2565 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2566 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2567 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2568 | } |
| 2569 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2570 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2571 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2572 | } |
| 2573 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2574 | static void |
| 2575 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2576 | { |
| 2577 | popup_grab_end(grab->pointer); |
| 2578 | } |
| 2579 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2580 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2581 | popup_grab_focus, |
| 2582 | popup_grab_motion, |
| 2583 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2584 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2585 | }; |
| 2586 | |
| 2587 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2588 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2589 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2590 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2591 | struct shell_seat *shseat = |
| 2592 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2593 | struct shell_surface *shsurf; |
| 2594 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2595 | |
| 2596 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2597 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2598 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2599 | shseat->popup_grab.grab.interface = NULL; |
| 2600 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2601 | /* Send the popup_done event to all the popups open */ |
| 2602 | 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] | 2603 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2604 | shsurf->popup.shseat = NULL; |
| 2605 | if (prev) { |
| 2606 | wl_list_init(&prev->popup.grab_link); |
| 2607 | } |
| 2608 | prev = shsurf; |
| 2609 | } |
| 2610 | wl_list_init(&prev->popup.grab_link); |
| 2611 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | static void |
| 2616 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2617 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2618 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2619 | |
| 2620 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2621 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2622 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2623 | /* We must make sure here that this popup was opened after |
| 2624 | * a mouse press, and not just by moving around with other |
| 2625 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2626 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2627 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2628 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2629 | 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] | 2630 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2631 | } else { |
| 2632 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2633 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | static void |
| 2637 | remove_popup_grab(struct shell_surface *shsurf) |
| 2638 | { |
| 2639 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2640 | |
| 2641 | wl_list_remove(&shsurf->popup.grab_link); |
| 2642 | wl_list_init(&shsurf->popup.grab_link); |
| 2643 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2644 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2645 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2650 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2651 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2652 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2653 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2654 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2655 | shsurf->surface->output = parent_view->output; |
| 2656 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2657 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2658 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 2659 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 2660 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2661 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2662 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2663 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2664 | } else { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2665 | wl_shell_surface_send_popup_done(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2666 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2667 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | static void |
| 2671 | shell_surface_set_popup(struct wl_client *client, |
| 2672 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2673 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2674 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2675 | struct wl_resource *parent_resource, |
| 2676 | int32_t x, int32_t y, uint32_t flags) |
| 2677 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2678 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2679 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2680 | shsurf->type = SHELL_SURFACE_POPUP; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2681 | shsurf->parent = wl_resource_get_user_data(parent_resource); |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 2682 | 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] | 2683 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2684 | shsurf->popup.x = x; |
| 2685 | shsurf->popup.y = y; |
| 2686 | } |
| 2687 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2688 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2689 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2690 | shell_surface_move, |
| 2691 | shell_surface_resize, |
| 2692 | shell_surface_set_toplevel, |
| 2693 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2694 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2695 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2696 | shell_surface_set_maximized, |
| 2697 | shell_surface_set_title, |
| 2698 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2699 | }; |
| 2700 | |
| 2701 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2702 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2703 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2704 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 2705 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2706 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2707 | remove_popup_grab(shsurf); |
| 2708 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2709 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2710 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2711 | shell_surface_is_top_fullscreen(shsurf)) |
| 2712 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2713 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2714 | if (shsurf->fullscreen.black_view) |
| 2715 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2716 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2717 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2718 | * we can always remove the listener. |
| 2719 | */ |
| 2720 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2721 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2722 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2723 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2724 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2725 | weston_view_destroy(shsurf->view); |
| 2726 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2727 | wl_list_remove(&shsurf->link); |
| 2728 | free(shsurf); |
| 2729 | } |
| 2730 | |
| 2731 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2732 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2733 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2734 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2735 | |
| 2736 | destroy_shell_surface(shsurf); |
| 2737 | } |
| 2738 | |
| 2739 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2740 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2741 | { |
| 2742 | struct shell_surface *shsurf = container_of(listener, |
| 2743 | struct shell_surface, |
| 2744 | surface_destroy_listener); |
| 2745 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2746 | if (shsurf->resource) |
| 2747 | wl_resource_destroy(shsurf->resource); |
| 2748 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2749 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2750 | } |
| 2751 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2752 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2753 | 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] | 2754 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2755 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2756 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2757 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2758 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2759 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2760 | else |
| 2761 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2762 | } |
| 2763 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2764 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2765 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2766 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2767 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2768 | struct shell_surface *shsurf; |
| 2769 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2770 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2771 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2772 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2773 | } |
| 2774 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2775 | shsurf = calloc(1, sizeof *shsurf); |
| 2776 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2777 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2778 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2779 | } |
| 2780 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2781 | shsurf->view = weston_view_create(surface); |
| 2782 | if (!shsurf->view) { |
| 2783 | weston_log("no memory to allocate shell surface\n"); |
| 2784 | free(shsurf); |
| 2785 | return NULL; |
| 2786 | } |
| 2787 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2788 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2789 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2790 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2791 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2792 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2793 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2794 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2795 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2796 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2797 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2798 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2799 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2800 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2801 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2802 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2803 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2804 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2805 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2806 | |
| 2807 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2808 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2809 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2810 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2811 | /* empty when not in use */ |
| 2812 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2813 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2814 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2815 | wl_list_init(&shsurf->workspace_transform.link); |
| 2816 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2817 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2818 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2819 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2820 | shsurf->client = client; |
| 2821 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2822 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2823 | } |
| 2824 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2825 | static struct weston_view * |
| 2826 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 2827 | { |
| 2828 | return shsurf->view; |
| 2829 | } |
| 2830 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2831 | static void |
| 2832 | shell_get_shell_surface(struct wl_client *client, |
| 2833 | struct wl_resource *resource, |
| 2834 | uint32_t id, |
| 2835 | struct wl_resource *surface_resource) |
| 2836 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2837 | struct weston_surface *surface = |
| 2838 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2839 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2840 | struct shell_surface *shsurf; |
| 2841 | |
| 2842 | if (get_shell_surface(surface)) { |
| 2843 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2844 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2845 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2846 | return; |
| 2847 | } |
| 2848 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2849 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2850 | if (!shsurf) { |
| 2851 | wl_resource_post_error(surface_resource, |
| 2852 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2853 | "surface->configure already set"); |
| 2854 | return; |
| 2855 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2856 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2857 | shsurf->resource = |
| 2858 | wl_resource_create(client, |
| 2859 | &wl_shell_surface_interface, 1, id); |
| 2860 | wl_resource_set_implementation(shsurf->resource, |
| 2861 | &shell_surface_implementation, |
| 2862 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 2866 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2867 | }; |
| 2868 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2869 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 2870 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 2871 | |
| 2872 | static int |
| 2873 | screensaver_timeout(void *data) |
| 2874 | { |
| 2875 | struct desktop_shell *shell = data; |
| 2876 | |
| 2877 | shell_fade(shell, FADE_OUT); |
| 2878 | |
| 2879 | return 1; |
| 2880 | } |
| 2881 | |
| 2882 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2883 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2884 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2885 | struct desktop_shell *shell = |
| 2886 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2887 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2888 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2889 | |
| 2890 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 2891 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2892 | } |
| 2893 | |
| 2894 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2895 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2896 | { |
| 2897 | if (shell->screensaver.binding) |
| 2898 | return; |
| 2899 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2900 | if (!shell->screensaver.path) { |
| 2901 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2902 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2903 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2904 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2905 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2906 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2907 | return; |
| 2908 | } |
| 2909 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2910 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2911 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2912 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2913 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2917 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2918 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2919 | if (shell->screensaver.process.pid == 0) |
| 2920 | return; |
| 2921 | |
| 2922 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2926 | 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] | 2927 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2928 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2929 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2930 | if (width == 0) |
| 2931 | return; |
| 2932 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2933 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 2934 | if (v->output == ev->output && v != ev) { |
| 2935 | weston_view_unmap(v); |
| 2936 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2937 | } |
| 2938 | } |
| 2939 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2940 | 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] | 2941 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2942 | if (wl_list_empty(&ev->layer_link)) { |
| 2943 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 2944 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2949 | 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] | 2950 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2951 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2952 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2953 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2954 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2955 | |
| 2956 | configure_static_view(view, &shell->background_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2960 | desktop_shell_set_background(struct wl_client *client, |
| 2961 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2962 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2963 | struct wl_resource *surface_resource) |
| 2964 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2965 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2966 | struct weston_surface *surface = |
| 2967 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2968 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2969 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2970 | if (surface->configure) { |
| 2971 | wl_resource_post_error(surface_resource, |
| 2972 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2973 | "surface role already assigned"); |
| 2974 | return; |
| 2975 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2976 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2977 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 2978 | weston_view_destroy(view); |
| 2979 | view = weston_view_create(surface); |
| 2980 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2981 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2982 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2983 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2984 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2985 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2986 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2987 | surface->output->width, |
| 2988 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2992 | 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] | 2993 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2994 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2995 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2996 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2997 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 2998 | |
| 2999 | configure_static_view(view, &shell->panel_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3003 | desktop_shell_set_panel(struct wl_client *client, |
| 3004 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3005 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3006 | struct wl_resource *surface_resource) |
| 3007 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3008 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3009 | struct weston_surface *surface = |
| 3010 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3011 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3012 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3013 | if (surface->configure) { |
| 3014 | wl_resource_post_error(surface_resource, |
| 3015 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3016 | "surface role already assigned"); |
| 3017 | return; |
| 3018 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3019 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3020 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3021 | weston_view_destroy(view); |
| 3022 | view = weston_view_create(surface); |
| 3023 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3024 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3025 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3026 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3027 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3028 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3029 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3030 | surface->output->width, |
| 3031 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3032 | } |
| 3033 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3034 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3035 | 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] | 3036 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3037 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3038 | struct weston_view *view; |
| 3039 | |
| 3040 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3041 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3042 | if (width == 0) |
| 3043 | return; |
| 3044 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3045 | surface->width = width; |
| 3046 | surface->height = height; |
| 3047 | view->geometry.width = width; |
| 3048 | view->geometry.height = height; |
| 3049 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3050 | |
| 3051 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3052 | wl_list_insert(&shell->lock_layer.view_list, |
| 3053 | &view->layer_link); |
| 3054 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3055 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3060 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3061 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3062 | struct desktop_shell *shell = |
| 3063 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3064 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3065 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3066 | shell->lock_surface = NULL; |
| 3067 | } |
| 3068 | |
| 3069 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3070 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3071 | struct wl_resource *resource, |
| 3072 | struct wl_resource *surface_resource) |
| 3073 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3074 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3075 | struct weston_surface *surface = |
| 3076 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3077 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3078 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3079 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3080 | if (!shell->locked) |
| 3081 | return; |
| 3082 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3083 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3084 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3085 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3086 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3087 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3088 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3089 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3090 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3091 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3095 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3096 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3097 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3098 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3099 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3100 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3101 | wl_list_remove(&shell->lock_layer.link); |
| 3102 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3103 | &shell->fullscreen_layer.link); |
| 3104 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3105 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3106 | if (shell->showing_input_panels) { |
| 3107 | wl_list_insert(&shell->panel_layer.link, |
| 3108 | &shell->input_panel_layer.link); |
| 3109 | wl_list_insert(&shell->input_panel_layer.link, |
| 3110 | &ws->layer.link); |
| 3111 | } else { |
| 3112 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3113 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3114 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3115 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3116 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3117 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3118 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3119 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | static void |
| 3123 | desktop_shell_unlock(struct wl_client *client, |
| 3124 | struct wl_resource *resource) |
| 3125 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3126 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3127 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3128 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3129 | |
| 3130 | if (shell->locked) |
| 3131 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3132 | } |
| 3133 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3134 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3135 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3136 | struct wl_resource *resource, |
| 3137 | struct wl_resource *surface_resource) |
| 3138 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3139 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3140 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3141 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3142 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3143 | } |
| 3144 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3145 | static void |
| 3146 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3147 | struct wl_resource *resource) |
| 3148 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3149 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3150 | |
| 3151 | shell_fade_startup(shell); |
| 3152 | } |
| 3153 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3154 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3155 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3156 | desktop_shell_set_panel, |
| 3157 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3158 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3159 | desktop_shell_set_grab_surface, |
| 3160 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3161 | }; |
| 3162 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3163 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3164 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3165 | { |
| 3166 | struct shell_surface *shsurf; |
| 3167 | |
| 3168 | shsurf = get_shell_surface(surface); |
| 3169 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3170 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3171 | return shsurf->type; |
| 3172 | } |
| 3173 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3174 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3175 | 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] | 3176 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3177 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3178 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3179 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3180 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3181 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3182 | if (surface == NULL) |
| 3183 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3184 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3185 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3186 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3187 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3188 | return; |
| 3189 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3190 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3194 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3195 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3196 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3197 | struct weston_surface *surface; |
| 3198 | struct shell_surface *shsurf; |
| 3199 | |
| 3200 | surface = weston_surface_get_main_surface(focus); |
| 3201 | if (surface == NULL) |
| 3202 | return; |
| 3203 | |
| 3204 | shsurf = get_shell_surface(surface); |
| 3205 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3206 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
| 3207 | return; |
| 3208 | |
| 3209 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3210 | } |
| 3211 | |
| 3212 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3213 | 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] | 3214 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3215 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3216 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3217 | uint32_t edges = 0; |
| 3218 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3219 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3220 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3221 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3222 | if (surface == NULL) |
| 3223 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3224 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3225 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3226 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 3227 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3228 | return; |
| 3229 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3230 | weston_view_from_global(shsurf->view, |
| 3231 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3232 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3233 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3234 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3235 | if (x < shsurf->view->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3236 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3237 | else if (x < 2 * shsurf->view->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3238 | edges |= 0; |
| 3239 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3240 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3242 | if (y < shsurf->view->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3243 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3244 | else if (y < 2 * shsurf->view->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3245 | edges |= 0; |
| 3246 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3247 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3248 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3249 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3253 | 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] | 3254 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3255 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3256 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3257 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3258 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3259 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3260 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3261 | /* XXX: broken for windows containing sub-surfaces */ |
| 3262 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3263 | if (surface == NULL) |
| 3264 | return; |
| 3265 | |
| 3266 | shsurf = get_shell_surface(surface); |
| 3267 | if (!shsurf) |
| 3268 | return; |
| 3269 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3270 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3271 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3272 | if (shsurf->view->alpha > 1.0) |
| 3273 | shsurf->view->alpha = 1.0; |
| 3274 | if (shsurf->view->alpha < step) |
| 3275 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3276 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3277 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3278 | weston_surface_damage(surface); |
| 3279 | } |
| 3280 | |
| 3281 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3282 | 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] | 3283 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3284 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3285 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 3286 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3287 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3288 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3289 | |
| 3290 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3291 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3292 | wl_fixed_to_double(seat->pointer->x), |
| 3293 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 3294 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3295 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3296 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3297 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3298 | increment = -output->zoom.increment; |
| 3299 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3300 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 3301 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3302 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3303 | else |
| 3304 | increment = 0; |
| 3305 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 3306 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 3307 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3308 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3309 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3310 | else if (output->zoom.level > output->zoom.max_level) |
| 3311 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 3312 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 3313 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 3314 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3315 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3316 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3317 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3318 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3319 | } |
| 3320 | } |
| 3321 | } |
| 3322 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3323 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3324 | 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] | 3325 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3326 | { |
| 3327 | do_zoom(seat, time, 0, axis, value); |
| 3328 | } |
| 3329 | |
| 3330 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3331 | 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] | 3332 | void *data) |
| 3333 | { |
| 3334 | do_zoom(seat, time, key, 0, 0); |
| 3335 | } |
| 3336 | |
| 3337 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3338 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3339 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3340 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3341 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3342 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3343 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3347 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 3348 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3349 | { |
| 3350 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3351 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3352 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3353 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3354 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3355 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 3356 | weston_pointer_move(pointer, x, y); |
| 3357 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3358 | if (!shsurf) |
| 3359 | return; |
| 3360 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3361 | cx = 0.5f * shsurf->view->geometry.width; |
| 3362 | cy = 0.5f * shsurf->view->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3363 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3364 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 3365 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3366 | r = sqrtf(dx * dx + dy * dy); |
| 3367 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3368 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3369 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3370 | |
| 3371 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3372 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3373 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3374 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3375 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3376 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3377 | |
| 3378 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3379 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3380 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3381 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 3382 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3383 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 3384 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3385 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3386 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3387 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3388 | wl_list_init(&shsurf->rotation.transform.link); |
| 3389 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3390 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3391 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3392 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3393 | /* We need to adjust the position of the surface |
| 3394 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3395 | cposx = shsurf->view->geometry.x + cx; |
| 3396 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3397 | dposx = rotate->center.x - cposx; |
| 3398 | dposy = rotate->center.y - cposy; |
| 3399 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3400 | weston_view_set_position(shsurf->view, |
| 3401 | shsurf->view->geometry.x + dposx, |
| 3402 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3403 | } |
| 3404 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 3405 | /* Repaint implies weston_surface_update_transform(), which |
| 3406 | * lazily applies the damage due to rotation update. |
| 3407 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3408 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3412 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 3413 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3414 | { |
| 3415 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3416 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3417 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3418 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3419 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3420 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 3421 | if (pointer->button_count == 0 && |
| 3422 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 3423 | if (shsurf) |
| 3424 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 3425 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3426 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3427 | free(rotate); |
| 3428 | } |
| 3429 | } |
| 3430 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3431 | static void |
| 3432 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 3433 | { |
| 3434 | struct rotate_grab *rotate = |
| 3435 | container_of(grab, struct rotate_grab, base.grab); |
| 3436 | |
| 3437 | shell_grab_end(&rotate->base); |
| 3438 | free(rotate); |
| 3439 | } |
| 3440 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 3441 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3442 | noop_grab_focus, |
| 3443 | rotate_grab_motion, |
| 3444 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 3445 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3446 | }; |
| 3447 | |
| 3448 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3449 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3450 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3451 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3452 | float dx, dy; |
| 3453 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3454 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3455 | rotate = malloc(sizeof *rotate); |
| 3456 | if (!rotate) |
| 3457 | return; |
| 3458 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3459 | weston_view_to_global_float(surface->view, |
| 3460 | surface->view->geometry.width * 0.5f, |
| 3461 | surface->view->geometry.height * 0.5f, |
| 3462 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3463 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3464 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 3465 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3466 | r = sqrtf(dx * dx + dy * dy); |
| 3467 | if (r > 20.0f) { |
| 3468 | struct weston_matrix inverse; |
| 3469 | |
| 3470 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3471 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3472 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 3473 | |
| 3474 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3475 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3476 | } else { |
| 3477 | weston_matrix_init(&surface->rotation.rotation); |
| 3478 | weston_matrix_init(&rotate->rotation); |
| 3479 | } |
| 3480 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3481 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 3482 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3486 | 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] | 3487 | void *data) |
| 3488 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3489 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3490 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3491 | struct shell_surface *surface; |
| 3492 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3493 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3494 | if (base_surface == NULL) |
| 3495 | return; |
| 3496 | |
| 3497 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 3498 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 3499 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 3500 | return; |
| 3501 | |
| 3502 | surface_rotate(surface, seat); |
| 3503 | } |
| 3504 | |
| 3505 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3506 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 3507 | { |
| 3508 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3509 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3510 | |
| 3511 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3512 | wl_list_for_each_reverse_safe(view, prev, |
| 3513 | &shell->fullscreen_layer.view_list, |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3514 | layer_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3515 | weston_view_restack(view, &ws->layer.view_list); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3519 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3520 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3521 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3522 | struct weston_surface *main_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3523 | struct weston_view *main_view; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3524 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3525 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3526 | struct weston_surface *old_es; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3527 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3528 | main_surface = weston_surface_get_main_surface(es); |
| 3529 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3530 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3531 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 3532 | state = ensure_focus_state(shell, seat); |
| 3533 | if (state == NULL) |
| 3534 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3535 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3536 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3537 | state->keyboard_focus = es; |
| 3538 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3539 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3540 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3541 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3542 | case SHELL_SURFACE_FULLSCREEN: |
| 3543 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3544 | shell_stack_fullscreen(get_shell_surface(main_surface)); |
| 3545 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3546 | return; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3547 | default: |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3548 | restore_all_output_modes(shell->compositor); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3549 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3550 | main_view = get_default_view(main_surface); |
| 3551 | if (main_view) |
| 3552 | weston_view_restack(main_view, &ws->layer.view_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3553 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3554 | } |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 3555 | |
| 3556 | if (shell->focus_animation_type != ANIMATION_NONE) |
| 3557 | 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] | 3558 | } |
| 3559 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3560 | /* no-op func for checking black surface */ |
| 3561 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3562 | 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] | 3563 | { |
| 3564 | } |
| 3565 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 3566 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3567 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 3568 | { |
| 3569 | if (es->configure == black_surface_configure) { |
| 3570 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3571 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 3572 | return true; |
| 3573 | } |
| 3574 | return false; |
| 3575 | } |
| 3576 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3577 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3578 | activate_binding(struct weston_seat *seat, |
| 3579 | struct desktop_shell *shell, |
| 3580 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3581 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3582 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3583 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 3584 | if (!focus) |
| 3585 | return; |
| 3586 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3587 | if (is_black_surface(focus, &main_surface)) |
| 3588 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3589 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3590 | main_surface = weston_surface_get_main_surface(focus); |
| 3591 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3592 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 3593 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3594 | activate(shell, focus, seat); |
| 3595 | } |
| 3596 | |
| 3597 | static void |
| 3598 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 3599 | void *data) |
| 3600 | { |
| 3601 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 3602 | return; |
| 3603 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3604 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | static void |
| 3608 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3609 | { |
| 3610 | if (seat->touch->grab != &seat->touch->default_grab) |
| 3611 | return; |
| 3612 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3613 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 3614 | } |
| 3615 | |
| 3616 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3617 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3618 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3619 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3620 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3621 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3622 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3623 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3624 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3625 | |
| 3626 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3627 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3628 | /* Hide all surfaces by removing the fullscreen, panel and |
| 3629 | * toplevel layers. This way nothing else can show or receive |
| 3630 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3631 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3632 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3633 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3634 | if (shell->showing_input_panels) |
| 3635 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3636 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3637 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3638 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3639 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3640 | launch_screensaver(shell); |
| 3641 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3642 | /* TODO: disable bindings that should not work while locked. */ |
| 3643 | |
| 3644 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3648 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3649 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3650 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3651 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3652 | return; |
| 3653 | } |
| 3654 | |
| 3655 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3656 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3657 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3658 | return; |
| 3659 | } |
| 3660 | |
| 3661 | if (shell->prepare_event_sent) |
| 3662 | return; |
| 3663 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3664 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3665 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3669 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3670 | { |
| 3671 | struct desktop_shell *shell = data; |
| 3672 | |
| 3673 | shell->fade.animation = NULL; |
| 3674 | |
| 3675 | switch (shell->fade.type) { |
| 3676 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3677 | weston_surface_destroy(shell->fade.view->surface); |
| 3678 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3679 | break; |
| 3680 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3681 | lock(shell); |
| 3682 | break; |
| 3683 | } |
| 3684 | } |
| 3685 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3686 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3687 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3688 | { |
| 3689 | struct weston_compositor *compositor = shell->compositor; |
| 3690 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3691 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3692 | |
| 3693 | surface = weston_surface_create(compositor); |
| 3694 | if (!surface) |
| 3695 | return NULL; |
| 3696 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3697 | view = weston_view_create(surface); |
| 3698 | if (!view) { |
| 3699 | weston_surface_destroy(surface); |
| 3700 | return NULL; |
| 3701 | } |
| 3702 | |
| 3703 | weston_view_configure(view, 0, 0, 8192, 8192); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3704 | 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] | 3705 | wl_list_insert(&compositor->fade_layer.view_list, |
| 3706 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3707 | pixman_region32_init(&surface->input); |
| 3708 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3709 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | static void |
| 3713 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 3714 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3715 | float tint; |
| 3716 | |
| 3717 | switch (type) { |
| 3718 | case FADE_IN: |
| 3719 | tint = 0.0; |
| 3720 | break; |
| 3721 | case FADE_OUT: |
| 3722 | tint = 1.0; |
| 3723 | break; |
| 3724 | default: |
| 3725 | weston_log("shell: invalid fade type\n"); |
| 3726 | return; |
| 3727 | } |
| 3728 | |
| 3729 | shell->fade.type = type; |
| 3730 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3731 | if (shell->fade.view == NULL) { |
| 3732 | shell->fade.view = shell_fade_create_surface(shell); |
| 3733 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3734 | return; |
| 3735 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3736 | shell->fade.view->alpha = 1.0 - tint; |
| 3737 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 3741 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3742 | else |
| 3743 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3744 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 3745 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3746 | shell_fade_done, shell); |
| 3747 | } |
| 3748 | |
| 3749 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3750 | do_shell_fade_startup(void *data) |
| 3751 | { |
| 3752 | struct desktop_shell *shell = data; |
| 3753 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 3754 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 3755 | shell_fade(shell, FADE_IN); |
| 3756 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3757 | weston_surface_destroy(shell->fade.view->surface); |
| 3758 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 3759 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | static void |
| 3763 | shell_fade_startup(struct desktop_shell *shell) |
| 3764 | { |
| 3765 | struct wl_event_loop *loop; |
| 3766 | |
| 3767 | if (!shell->fade.startup_timer) |
| 3768 | return; |
| 3769 | |
| 3770 | wl_event_source_remove(shell->fade.startup_timer); |
| 3771 | shell->fade.startup_timer = NULL; |
| 3772 | |
| 3773 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 3774 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 3775 | } |
| 3776 | |
| 3777 | static int |
| 3778 | fade_startup_timeout(void *data) |
| 3779 | { |
| 3780 | struct desktop_shell *shell = data; |
| 3781 | |
| 3782 | shell_fade_startup(shell); |
| 3783 | return 0; |
| 3784 | } |
| 3785 | |
| 3786 | static void |
| 3787 | shell_fade_init(struct desktop_shell *shell) |
| 3788 | { |
| 3789 | /* Make compositor output all black, and wait for the desktop-shell |
| 3790 | * client to signal it is ready, then fade in. The timer triggers a |
| 3791 | * fade-in, in case the desktop-shell client takes too long. |
| 3792 | */ |
| 3793 | |
| 3794 | struct wl_event_loop *loop; |
| 3795 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3796 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3797 | weston_log("%s: warning: fade surface already exists\n", |
| 3798 | __func__); |
| 3799 | return; |
| 3800 | } |
| 3801 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3802 | shell->fade.view = shell_fade_create_surface(shell); |
| 3803 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3804 | return; |
| 3805 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3806 | weston_view_update_transform(shell->fade.view); |
| 3807 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3808 | |
| 3809 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 3810 | shell->fade.startup_timer = |
| 3811 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 3812 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 3813 | } |
| 3814 | |
| 3815 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3816 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3817 | { |
| 3818 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3819 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3820 | |
| 3821 | shell_fade(shell, FADE_OUT); |
| 3822 | /* lock() is called from shell_fade_done() */ |
| 3823 | } |
| 3824 | |
| 3825 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3826 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3827 | { |
| 3828 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3829 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3830 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3831 | unlock(shell); |
| 3832 | } |
| 3833 | |
| 3834 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3835 | show_input_panels(struct wl_listener *listener, void *data) |
| 3836 | { |
| 3837 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3838 | container_of(listener, struct desktop_shell, |
| 3839 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3840 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3841 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3842 | shell->text_input.surface = (struct weston_surface*)data; |
| 3843 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 3844 | if (shell->showing_input_panels) |
| 3845 | return; |
| 3846 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3847 | shell->showing_input_panels = true; |
| 3848 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 3849 | if (!shell->locked) |
| 3850 | wl_list_insert(&shell->panel_layer.link, |
| 3851 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3852 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3853 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3854 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3855 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3856 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3857 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 3858 | &ipsurf->view->layer_link); |
| 3859 | weston_view_geometry_dirty(ipsurf->view); |
| 3860 | weston_view_update_transform(ipsurf->view); |
| 3861 | weston_surface_damage(ipsurf->surface); |
| 3862 | weston_slide_run(ipsurf->view, ipsurf->view->geometry.height, |
| 3863 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | static void |
| 3868 | hide_input_panels(struct wl_listener *listener, void *data) |
| 3869 | { |
| 3870 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3871 | container_of(listener, struct desktop_shell, |
| 3872 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3873 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3874 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 3875 | if (!shell->showing_input_panels) |
| 3876 | return; |
| 3877 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3878 | shell->showing_input_panels = false; |
| 3879 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 3880 | if (!shell->locked) |
| 3881 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3882 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3883 | wl_list_for_each_safe(view, next, |
| 3884 | &shell->input_panel_layer.view_list, layer_link) |
| 3885 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3886 | } |
| 3887 | |
| 3888 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3889 | update_input_panels(struct wl_listener *listener, void *data) |
| 3890 | { |
| 3891 | struct desktop_shell *shell = |
| 3892 | container_of(listener, struct desktop_shell, |
| 3893 | update_input_panel_listener); |
| 3894 | |
| 3895 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 3896 | } |
| 3897 | |
| 3898 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3899 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3900 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3901 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3902 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3903 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3904 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3905 | |
| 3906 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 3907 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3908 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3909 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3910 | } |
| 3911 | |
| 3912 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3913 | weston_view_set_initial_position(struct weston_view *view, |
| 3914 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3915 | { |
| 3916 | struct weston_compositor *compositor = shell->compositor; |
| 3917 | int ix = 0, iy = 0; |
| 3918 | int range_x, range_y; |
| 3919 | int dx, dy, x, y, panel_height; |
| 3920 | struct weston_output *output, *target_output = NULL; |
| 3921 | struct weston_seat *seat; |
| 3922 | |
| 3923 | /* As a heuristic place the new window on the same output as the |
| 3924 | * pointer. Falling back to the output containing 0, 0. |
| 3925 | * |
| 3926 | * TODO: Do something clever for touch too? |
| 3927 | */ |
| 3928 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 3929 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3930 | ix = wl_fixed_to_int(seat->pointer->x); |
| 3931 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3932 | break; |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3937 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 3938 | target_output = output; |
| 3939 | break; |
| 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3944 | weston_view_set_position(view, 10 + random() % 400, |
| 3945 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3946 | return; |
| 3947 | } |
| 3948 | |
| 3949 | /* Valid range within output where the surface will still be onscreen. |
| 3950 | * If this is negative it means that the surface is bigger than |
| 3951 | * output. |
| 3952 | */ |
| 3953 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3954 | range_x = target_output->width - view->geometry.width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3955 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3956 | view->geometry.height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3957 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 3958 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3959 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3960 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 3961 | dx = 0; |
| 3962 | |
| 3963 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3964 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 3965 | else |
| 3966 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3967 | |
| 3968 | x = target_output->x + dx; |
| 3969 | y = target_output->y + dy; |
| 3970 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3971 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3975 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 3976 | 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] | 3977 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3978 | struct weston_compositor *compositor = shell->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3979 | struct weston_view *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 3980 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3981 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3982 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3983 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3984 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3985 | shsurf->view->geometry.width = width; |
| 3986 | shsurf->view->geometry.height = height; |
| 3987 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3988 | |
| 3989 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3990 | switch (shsurf->type) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3991 | case SHELL_SURFACE_TOPLEVEL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3992 | weston_view_set_initial_position(shsurf->view, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3993 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3994 | case SHELL_SURFACE_FULLSCREEN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3995 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3996 | shell_map_fullscreen(shsurf); |
| 3997 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3998 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3999 | /* use surface configure to set the geometry */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4000 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4001 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4002 | &surf_x, &surf_y, NULL, NULL); |
| 4003 | weston_view_set_position(shsurf->view, |
| 4004 | shsurf->output->x - surf_x, |
| 4005 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4006 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4007 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4008 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4009 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4010 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4011 | weston_view_set_position(shsurf->view, |
| 4012 | shsurf->view->geometry.x + sx, |
| 4013 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4014 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4015 | default: |
| 4016 | ; |
| 4017 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4018 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 4019 | /* surface stacking order, see also activate() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4020 | switch (shsurf->type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4021 | case SHELL_SURFACE_POPUP: |
| 4022 | case SHELL_SURFACE_TRANSIENT: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4023 | /* TODO: Handle a parent with multiple views */ |
| 4024 | parent = get_default_view(shsurf->parent); |
| 4025 | if (parent) { |
| 4026 | wl_list_remove(&shsurf->view->layer_link); |
| 4027 | wl_list_insert(parent->layer_link.prev, |
| 4028 | &shsurf->view->layer_link); |
| 4029 | } |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 4030 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4031 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 4032 | case SHELL_SURFACE_NONE: |
| 4033 | break; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4034 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4035 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4036 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4037 | wl_list_remove(&shsurf->view->layer_link); |
| 4038 | wl_list_insert(&ws->layer.view_list, &shsurf->view->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4039 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4040 | } |
| 4041 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4042 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 4043 | weston_view_update_transform(shsurf->view); |
| 4044 | if (shsurf->type == SHELL_SURFACE_MAXIMIZED) { |
| 4045 | shsurf->surface->output = shsurf->output; |
| 4046 | shsurf->view->output = shsurf->output; |
| 4047 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 4048 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 4049 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4050 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4051 | /* XXX: xwayland's using the same fields for transient type */ |
| 4052 | case SHELL_SURFACE_XWAYLAND: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4053 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 4054 | if (shsurf->transient.flags == |
| 4055 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 4056 | break; |
| 4057 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4058 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4059 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4060 | if (!shell->locked) { |
| 4061 | wl_list_for_each(seat, &compositor->seat_list, link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4062 | activate(shell, shsurf->surface, seat); |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4063 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 4064 | break; |
| 4065 | default: |
| 4066 | break; |
| 4067 | } |
| 4068 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4069 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4070 | { |
| 4071 | switch (shell->win_animation_type) { |
| 4072 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4073 | 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] | 4074 | break; |
| 4075 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4076 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 4077 | break; |
| 4078 | default: |
| 4079 | break; |
| 4080 | } |
| 4081 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4085 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4086 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4087 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4088 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 4089 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4090 | struct weston_view *view; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4091 | int32_t surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4092 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4093 | shsurf = get_shell_surface(surface); |
| 4094 | if (shsurf) |
| 4095 | surface_type = shsurf->type; |
| 4096 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4097 | /* TODO: |
| 4098 | * This should probably be changed to be more shell_surface |
| 4099 | * dependent |
| 4100 | */ |
| 4101 | wl_list_for_each(view, &surface->views, surface_link) |
| 4102 | weston_view_configure(view, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4103 | |
| 4104 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4105 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 4106 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4107 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4108 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4109 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4110 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4111 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 4112 | NULL, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4113 | shsurf->view->geometry.x = shsurf->output->x - surf_x; |
| 4114 | shsurf->view->geometry.y = shsurf->output->y + |
| 4115 | get_output_panel_height(shell,shsurf->output) - surf_y; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4116 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4117 | case SHELL_SURFACE_TOPLEVEL: |
| 4118 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4119 | default: |
| 4120 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 4121 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 4122 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4123 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 4124 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4125 | wl_list_for_each(view, &surface->views, surface_link) |
| 4126 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4127 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4128 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4129 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4130 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4131 | } |
| 4132 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4133 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4134 | 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] | 4135 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 4136 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4137 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4138 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 4139 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4140 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 4141 | if (!weston_surface_is_mapped(es) && |
| 4142 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 4143 | remove_popup_grab(shsurf); |
| 4144 | } |
| 4145 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4146 | if (width == 0) |
| 4147 | return; |
| 4148 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4149 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4150 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4151 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4152 | type_changed = 1; |
| 4153 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 4154 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4155 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4156 | map(shell, shsurf, width, height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 4157 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4158 | shsurf->view->geometry.width != width || |
| 4159 | shsurf->view->geometry.height != height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4160 | float from_x, from_y; |
| 4161 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4162 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4163 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 4164 | 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] | 4165 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4166 | shsurf->view->geometry.x + to_x - from_x, |
| 4167 | shsurf->view->geometry.y + to_y - from_y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4168 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 4169 | } |
| 4170 | } |
| 4171 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4172 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4173 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4174 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4175 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4176 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4177 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4178 | struct desktop_shell *shell = |
| 4179 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4180 | |
| 4181 | shell->child.process.pid = 0; |
| 4182 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4183 | |
| 4184 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 4185 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4186 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4187 | shell->child.deathstamp = time; |
| 4188 | shell->child.deathcount = 0; |
| 4189 | } |
| 4190 | |
| 4191 | shell->child.deathcount++; |
| 4192 | if (shell->child.deathcount > 5) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4193 | weston_log("weston-desktop-shell died, giving up.\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4194 | return; |
| 4195 | } |
| 4196 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4197 | weston_log("weston-desktop-shell died, respawning...\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 4198 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4199 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4200 | } |
| 4201 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4202 | static void |
| 4203 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4204 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4205 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 4206 | const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4207 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4208 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 4209 | &shell->child.process, |
| 4210 | shell_exe, |
| 4211 | desktop_shell_sigchld); |
| 4212 | |
| 4213 | if (!shell->child.client) |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4214 | weston_log("not able to start %s\n", shell_exe); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4218 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 4219 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4220 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4221 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4222 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4223 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 4224 | if (resource) |
| 4225 | wl_resource_set_implementation(resource, &shell_implementation, |
| 4226 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4227 | } |
| 4228 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4229 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4230 | unbind_desktop_shell(struct wl_resource *resource) |
| 4231 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4232 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 4233 | |
| 4234 | if (shell->locked) |
| 4235 | resume_desktop(shell); |
| 4236 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4237 | shell->child.desktop_shell = NULL; |
| 4238 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4242 | bind_desktop_shell(struct wl_client *client, |
| 4243 | void *data, uint32_t version, uint32_t id) |
| 4244 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4245 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4246 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4247 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4248 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 4249 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4250 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4251 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4252 | wl_resource_set_implementation(resource, |
| 4253 | &desktop_shell_implementation, |
| 4254 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4255 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4256 | |
| 4257 | if (version < 2) |
| 4258 | shell_fade_startup(shell); |
| 4259 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4260 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4261 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 4262 | |
| 4263 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4264 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4265 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4266 | } |
| 4267 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4268 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4269 | 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] | 4270 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4271 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4272 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4273 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4274 | if (width == 0) |
| 4275 | return; |
| 4276 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 4277 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4278 | if (!shell->locked) |
| 4279 | return; |
| 4280 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4281 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 4282 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4283 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4284 | if (wl_list_empty(&view->layer_link)) { |
| 4285 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 4286 | &view->layer_link); |
| 4287 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4288 | wl_event_source_timer_update(shell->screensaver.timer, |
| 4289 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4290 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4291 | } |
| 4292 | } |
| 4293 | |
| 4294 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4295 | screensaver_set_surface(struct wl_client *client, |
| 4296 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4297 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4298 | struct wl_resource *output_resource) |
| 4299 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4300 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4301 | struct weston_surface *surface = |
| 4302 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4303 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4304 | struct weston_view *view, *next; |
| 4305 | |
| 4306 | /* Make sure we only have one view */ |
| 4307 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 4308 | weston_view_destroy(view); |
| 4309 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4310 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 4311 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4312 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4313 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | static const struct screensaver_interface screensaver_implementation = { |
| 4317 | screensaver_set_surface |
| 4318 | }; |
| 4319 | |
| 4320 | static void |
| 4321 | unbind_screensaver(struct wl_resource *resource) |
| 4322 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4323 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4324 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4325 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | static void |
| 4329 | bind_screensaver(struct wl_client *client, |
| 4330 | void *data, uint32_t version, uint32_t id) |
| 4331 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4332 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4333 | struct wl_resource *resource; |
| 4334 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4335 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4336 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4337 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4338 | wl_resource_set_implementation(resource, |
| 4339 | &screensaver_implementation, |
| 4340 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4341 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4342 | return; |
| 4343 | } |
| 4344 | |
| 4345 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4346 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4347 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4348 | } |
| 4349 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4350 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4351 | 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] | 4352 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4353 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 4354 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4355 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4356 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4357 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 4358 | if (width == 0) |
| 4359 | return; |
| 4360 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4361 | if (!weston_surface_is_mapped(surface)) { |
| 4362 | if (!shell->showing_input_panels) |
| 4363 | return; |
| 4364 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4365 | show_surface = 1; |
| 4366 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 4367 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4368 | 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] | 4369 | |
| 4370 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4371 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 4372 | 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] | 4373 | } else { |
Rob Bradford | bdeb5d2 | 2013-07-11 13:20:53 +0100 | [diff] [blame] | 4374 | x = ip_surface->output->x + (ip_surface->output->width - width) / 2; |
| 4375 | y = ip_surface->output->y + ip_surface->output->height - height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4376 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4377 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4378 | weston_view_configure(ip_surface->view, x, y, width, height); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4379 | |
| 4380 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4381 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4382 | &ip_surface->view->layer_link); |
| 4383 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4384 | weston_surface_damage(surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4385 | 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] | 4386 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4387 | } |
| 4388 | |
| 4389 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4390 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4391 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4392 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 4393 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4394 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4395 | wl_list_remove(&input_panel_surface->link); |
| 4396 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4397 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4398 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4399 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4400 | free(input_panel_surface); |
| 4401 | } |
| 4402 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4403 | static struct input_panel_surface * |
| 4404 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4405 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4406 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4407 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4408 | } else { |
| 4409 | return NULL; |
| 4410 | } |
| 4411 | } |
| 4412 | |
| 4413 | static void |
| 4414 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4415 | { |
| 4416 | struct input_panel_surface *ipsurface = container_of(listener, |
| 4417 | struct input_panel_surface, |
| 4418 | surface_destroy_listener); |
| 4419 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4420 | if (ipsurface->resource) { |
| 4421 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4422 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4423 | destroy_input_panel_surface(ipsurface); |
| 4424 | } |
| 4425 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4426 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4427 | static struct input_panel_surface * |
| 4428 | create_input_panel_surface(struct desktop_shell *shell, |
| 4429 | struct weston_surface *surface) |
| 4430 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4431 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4432 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4433 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 4434 | if (!input_panel_surface) |
| 4435 | return NULL; |
| 4436 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4437 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4438 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4439 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4440 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4441 | |
| 4442 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4443 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4444 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4445 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4446 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4447 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4448 | &input_panel_surface->surface_destroy_listener); |
| 4449 | |
| 4450 | wl_list_init(&input_panel_surface->link); |
| 4451 | |
| 4452 | return input_panel_surface; |
| 4453 | } |
| 4454 | |
| 4455 | static void |
| 4456 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 4457 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 4458 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4459 | uint32_t position) |
| 4460 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4461 | struct input_panel_surface *input_panel_surface = |
| 4462 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4463 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4464 | |
| 4465 | wl_list_insert(&shell->input_panel.surfaces, |
| 4466 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4467 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4468 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4469 | input_panel_surface->panel = 0; |
| 4470 | } |
| 4471 | |
| 4472 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4473 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 4474 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4475 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4476 | struct input_panel_surface *input_panel_surface = |
| 4477 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4478 | struct desktop_shell *shell = input_panel_surface->shell; |
| 4479 | |
| 4480 | wl_list_insert(&shell->input_panel.surfaces, |
| 4481 | &input_panel_surface->link); |
| 4482 | |
| 4483 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4484 | } |
| 4485 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4486 | 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] | 4487 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 4488 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4489 | }; |
| 4490 | |
| 4491 | static void |
| 4492 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 4493 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 4494 | struct input_panel_surface *ipsurf = |
| 4495 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4496 | |
| 4497 | destroy_input_panel_surface(ipsurf); |
| 4498 | } |
| 4499 | |
| 4500 | static void |
| 4501 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 4502 | struct wl_resource *resource, |
| 4503 | uint32_t id, |
| 4504 | struct wl_resource *surface_resource) |
| 4505 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4506 | struct weston_surface *surface = |
| 4507 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4508 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4509 | struct input_panel_surface *ipsurf; |
| 4510 | |
| 4511 | if (get_input_panel_surface(surface)) { |
| 4512 | wl_resource_post_error(surface_resource, |
| 4513 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4514 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4515 | return; |
| 4516 | } |
| 4517 | |
| 4518 | ipsurf = create_input_panel_surface(shell, surface); |
| 4519 | if (!ipsurf) { |
| 4520 | wl_resource_post_error(surface_resource, |
| 4521 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4522 | "surface->configure already set"); |
| 4523 | return; |
| 4524 | } |
| 4525 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4526 | ipsurf->resource = |
| 4527 | wl_resource_create(client, |
| 4528 | &wl_input_panel_surface_interface, 1, id); |
| 4529 | wl_resource_set_implementation(ipsurf->resource, |
| 4530 | &input_panel_surface_implementation, |
| 4531 | ipsurf, |
| 4532 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4533 | } |
| 4534 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4535 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 4536 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4537 | }; |
| 4538 | |
| 4539 | static void |
| 4540 | unbind_input_panel(struct wl_resource *resource) |
| 4541 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 4542 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4543 | |
| 4544 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | static void |
| 4548 | bind_input_panel(struct wl_client *client, |
| 4549 | void *data, uint32_t version, uint32_t id) |
| 4550 | { |
| 4551 | struct desktop_shell *shell = data; |
| 4552 | struct wl_resource *resource; |
| 4553 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4554 | resource = wl_resource_create(client, |
| 4555 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4556 | |
| 4557 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4558 | wl_resource_set_implementation(resource, |
| 4559 | &input_panel_implementation, |
| 4560 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4561 | shell->input_panel.binding = resource; |
| 4562 | return; |
| 4563 | } |
| 4564 | |
| 4565 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 4566 | "interface object already bound"); |
| 4567 | wl_resource_destroy(resource); |
| 4568 | } |
| 4569 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4570 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4571 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4572 | struct weston_surface *current; |
| 4573 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4574 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4575 | }; |
| 4576 | |
| 4577 | static void |
| 4578 | switcher_next(struct switcher *switcher) |
| 4579 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4580 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4581 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4582 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4583 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4584 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4585 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 4586 | switch (get_shell_surface_type(view->surface)) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4587 | case SHELL_SURFACE_TOPLEVEL: |
| 4588 | case SHELL_SURFACE_FULLSCREEN: |
| 4589 | case SHELL_SURFACE_MAXIMIZED: |
| 4590 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4591 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4592 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4593 | next = view->surface; |
| 4594 | prev = view->surface; |
| 4595 | view->alpha = 0.25; |
| 4596 | weston_view_geometry_dirty(view); |
| 4597 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4598 | break; |
| 4599 | default: |
| 4600 | break; |
| 4601 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4602 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4603 | if (is_black_surface(view->surface, NULL)) { |
| 4604 | view->alpha = 0.25; |
| 4605 | weston_view_geometry_dirty(view); |
| 4606 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4607 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | if (next == NULL) |
| 4611 | next = first; |
| 4612 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4613 | if (next == NULL) |
| 4614 | return; |
| 4615 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4616 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4617 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4618 | |
| 4619 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4620 | wl_list_for_each(view, &next->views, surface_link) |
| 4621 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 4622 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 4623 | shsurf = get_shell_surface(switcher->current); |
| 4624 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4625 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4629 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4630 | { |
| 4631 | struct switcher *switcher = |
| 4632 | container_of(listener, struct switcher, listener); |
| 4633 | |
| 4634 | switcher_next(switcher); |
| 4635 | } |
| 4636 | |
| 4637 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4638 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4639 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4640 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4641 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4642 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4643 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4644 | 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] | 4645 | if (is_focus_view(view)) |
| 4646 | continue; |
| 4647 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4648 | view->alpha = 1.0; |
| 4649 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4650 | } |
| 4651 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 4652 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4653 | activate(switcher->shell, switcher->current, |
| 4654 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4655 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4656 | weston_keyboard_end_grab(keyboard); |
| 4657 | if (keyboard->input_method_resource) |
| 4658 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4659 | free(switcher); |
| 4660 | } |
| 4661 | |
| 4662 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4663 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4664 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4665 | { |
| 4666 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4667 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4668 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 4669 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4670 | switcher_next(switcher); |
| 4671 | } |
| 4672 | |
| 4673 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4674 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4675 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4676 | uint32_t mods_locked, uint32_t group) |
| 4677 | { |
| 4678 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4679 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4680 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4681 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4682 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4683 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4684 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4685 | static void |
| 4686 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 4687 | { |
| 4688 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 4689 | |
| 4690 | switcher_destroy(switcher); |
| 4691 | } |
| 4692 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4693 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4694 | switcher_key, |
| 4695 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4696 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4697 | }; |
| 4698 | |
| 4699 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4700 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4701 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4702 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4703 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4704 | struct switcher *switcher; |
| 4705 | |
| 4706 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4707 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4708 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4709 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4710 | wl_list_init(&switcher->listener.link); |
| 4711 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4712 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4713 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4714 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4715 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 4716 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4717 | switcher_next(switcher); |
| 4718 | } |
| 4719 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame^] | 4720 | struct exposay_surface { |
| 4721 | struct desktop_shell *shell; |
| 4722 | struct weston_surface *surface; |
| 4723 | struct weston_view *view; |
| 4724 | struct wl_list link; |
| 4725 | |
| 4726 | int x; |
| 4727 | int y; |
| 4728 | int width; |
| 4729 | int height; |
| 4730 | double scale; |
| 4731 | |
| 4732 | int row; |
| 4733 | int column; |
| 4734 | |
| 4735 | /* The animations only apply a transformation for their own lifetime, |
| 4736 | * and don't have an option to indefinitely maintain the |
| 4737 | * transformation in a steady state - so, we apply our own once the |
| 4738 | * animation has finished. */ |
| 4739 | struct weston_transform transform; |
| 4740 | }; |
| 4741 | |
| 4742 | static void exposay_set_state(struct desktop_shell *shell, |
| 4743 | enum exposay_target_state state, |
| 4744 | struct weston_seat *seat); |
| 4745 | static void exposay_check_state(struct desktop_shell *shell); |
| 4746 | |
| 4747 | static void |
| 4748 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 4749 | { |
| 4750 | shell->exposay.in_flight++; |
| 4751 | } |
| 4752 | |
| 4753 | static void |
| 4754 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 4755 | { |
| 4756 | if (--shell->exposay.in_flight > 0) |
| 4757 | return; |
| 4758 | |
| 4759 | exposay_check_state(shell); |
| 4760 | } |
| 4761 | |
| 4762 | static void |
| 4763 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 4764 | { |
| 4765 | struct exposay_surface *esurface = data; |
| 4766 | |
| 4767 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 4768 | &esurface->transform.link); |
| 4769 | weston_matrix_init(&esurface->transform.matrix); |
| 4770 | weston_matrix_scale(&esurface->transform.matrix, |
| 4771 | esurface->scale, esurface->scale, 1.0f); |
| 4772 | weston_matrix_translate(&esurface->transform.matrix, |
| 4773 | esurface->x - esurface->view->geometry.x, |
| 4774 | esurface->y - esurface->view->geometry.y, |
| 4775 | 0); |
| 4776 | |
| 4777 | weston_view_geometry_dirty(esurface->view); |
| 4778 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 4779 | |
| 4780 | exposay_in_flight_dec(esurface->shell); |
| 4781 | } |
| 4782 | |
| 4783 | static void |
| 4784 | exposay_animate_in(struct exposay_surface *esurface) |
| 4785 | { |
| 4786 | exposay_in_flight_inc(esurface->shell); |
| 4787 | |
| 4788 | weston_move_scale_run(esurface->view, |
| 4789 | esurface->x - esurface->view->geometry.x, |
| 4790 | esurface->y - esurface->view->geometry.y, |
| 4791 | 1.0, esurface->scale, 0, |
| 4792 | exposay_animate_in_done, esurface); |
| 4793 | } |
| 4794 | |
| 4795 | static void |
| 4796 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 4797 | { |
| 4798 | struct exposay_surface *esurface = data; |
| 4799 | struct desktop_shell *shell = esurface->shell; |
| 4800 | |
| 4801 | wl_list_remove(&esurface->link); |
| 4802 | free(esurface); |
| 4803 | |
| 4804 | exposay_in_flight_dec(shell); |
| 4805 | } |
| 4806 | |
| 4807 | static void |
| 4808 | exposay_animate_out(struct exposay_surface *esurface) |
| 4809 | { |
| 4810 | exposay_in_flight_inc(esurface->shell); |
| 4811 | |
| 4812 | /* Remove the static transformation set up by |
| 4813 | * exposay_transform_in_done(). */ |
| 4814 | wl_list_remove(&esurface->transform.link); |
| 4815 | weston_view_geometry_dirty(esurface->view); |
| 4816 | |
| 4817 | weston_move_scale_run(esurface->view, |
| 4818 | esurface->x - esurface->view->geometry.x, |
| 4819 | esurface->y - esurface->view->geometry.y, |
| 4820 | 1.0, esurface->scale, 1, |
| 4821 | exposay_animate_out_done, esurface); |
| 4822 | } |
| 4823 | |
| 4824 | static void |
| 4825 | exposay_highlight_surface(struct desktop_shell *shell, |
| 4826 | struct exposay_surface *esurface) |
| 4827 | { |
| 4828 | struct weston_view *view = NULL; |
| 4829 | |
| 4830 | if (esurface) { |
| 4831 | shell->exposay.row_current = esurface->row; |
| 4832 | shell->exposay.column_current = esurface->column; |
| 4833 | view = esurface->view; |
| 4834 | } |
| 4835 | |
| 4836 | animate_focus_change(shell, shell->exposay.workspace, |
| 4837 | shell->exposay.focus_current, view); |
| 4838 | shell->exposay.focus_current = view; |
| 4839 | } |
| 4840 | |
| 4841 | static int |
| 4842 | exposay_is_animating(struct desktop_shell *shell) |
| 4843 | { |
| 4844 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 4845 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 4846 | return 0; |
| 4847 | |
| 4848 | return (shell->exposay.in_flight > 0); |
| 4849 | } |
| 4850 | |
| 4851 | static void |
| 4852 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 4853 | { |
| 4854 | struct exposay_surface *esurface; |
| 4855 | |
| 4856 | if (exposay_is_animating(shell)) |
| 4857 | return; |
| 4858 | |
| 4859 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 4860 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 4861 | continue; |
| 4862 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 4863 | continue; |
| 4864 | |
| 4865 | exposay_highlight_surface(shell, esurface); |
| 4866 | return; |
| 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 4871 | * aspect ratio into account really. Also needs to be notified of surface |
| 4872 | * addition and removal and adjust layout/animate accordingly. */ |
| 4873 | static enum exposay_layout_state |
| 4874 | exposay_layout(struct desktop_shell *shell) |
| 4875 | { |
| 4876 | struct workspace *workspace = shell->exposay.workspace; |
| 4877 | struct weston_compositor *compositor = shell->compositor; |
| 4878 | struct weston_output *output = get_default_output(compositor); |
| 4879 | struct weston_view *view; |
| 4880 | struct exposay_surface *esurface; |
| 4881 | int w, h; |
| 4882 | int i; |
| 4883 | int last_row_removed = 0; |
| 4884 | |
| 4885 | wl_list_init(&shell->exposay.surface_list); |
| 4886 | |
| 4887 | shell->exposay.num_surfaces = 0; |
| 4888 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 4889 | if (!get_shell_surface(view->surface)) |
| 4890 | continue; |
| 4891 | shell->exposay.num_surfaces++; |
| 4892 | } |
| 4893 | |
| 4894 | if (shell->exposay.num_surfaces == 0) { |
| 4895 | shell->exposay.grid_size = 0; |
| 4896 | shell->exposay.hpadding_outer = 0; |
| 4897 | shell->exposay.vpadding_outer = 0; |
| 4898 | shell->exposay.padding_inner = 0; |
| 4899 | shell->exposay.surface_size = 0; |
| 4900 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 4901 | } |
| 4902 | |
| 4903 | /* Lay the grid out as square as possible, losing surfaces from the |
| 4904 | * bottom row if required. Start with fixed padding of a 10% margin |
| 4905 | * around the outside and 80px internal padding between surfaces, and |
| 4906 | * maximise the area made available to surfaces after this, but only |
| 4907 | * to a maximum of 1/3rd the total output size. |
| 4908 | * |
| 4909 | * If we can't make a square grid, add one extra row at the bottom |
| 4910 | * which will have a smaller number of columns. |
| 4911 | * |
| 4912 | * XXX: Surely there has to be a better way to express this maths, |
| 4913 | * right?! |
| 4914 | */ |
| 4915 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 4916 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 4917 | shell->exposay.grid_size++; |
| 4918 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 4919 | |
| 4920 | shell->exposay.hpadding_outer = (output->width / 10); |
| 4921 | shell->exposay.vpadding_outer = (output->height / 10); |
| 4922 | shell->exposay.padding_inner = 80; |
| 4923 | |
| 4924 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 4925 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 4926 | w /= shell->exposay.grid_size; |
| 4927 | |
| 4928 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 4929 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 4930 | h /= shell->exposay.grid_size; |
| 4931 | |
| 4932 | shell->exposay.surface_size = (w < h) ? w : h; |
| 4933 | if (shell->exposay.surface_size > (output->width / 2)) |
| 4934 | shell->exposay.surface_size = output->width / 2; |
| 4935 | if (shell->exposay.surface_size > (output->height / 2)) |
| 4936 | shell->exposay.surface_size = output->height / 2; |
| 4937 | |
| 4938 | i = 0; |
| 4939 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 4940 | int pad; |
| 4941 | |
| 4942 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 4943 | |
| 4944 | if (!get_shell_surface(view->surface)) |
| 4945 | continue; |
| 4946 | |
| 4947 | esurface = malloc(sizeof(*esurface)); |
| 4948 | if (!esurface) { |
| 4949 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 4950 | shell->exposay.seat); |
| 4951 | break; |
| 4952 | } |
| 4953 | |
| 4954 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 4955 | esurface->shell = shell; |
| 4956 | esurface->view = view; |
| 4957 | |
| 4958 | esurface->row = i / shell->exposay.grid_size; |
| 4959 | esurface->column = i % shell->exposay.grid_size; |
| 4960 | |
| 4961 | esurface->x = shell->exposay.hpadding_outer; |
| 4962 | esurface->x += pad * esurface->column; |
| 4963 | esurface->y = shell->exposay.vpadding_outer; |
| 4964 | esurface->y += pad * esurface->row; |
| 4965 | |
| 4966 | if (esurface->row == shell->exposay.grid_size - 1) |
| 4967 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 4968 | |
| 4969 | if (view->geometry.width > view->geometry.height) |
| 4970 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.width; |
| 4971 | else |
| 4972 | esurface->scale = shell->exposay.surface_size / (float) view->geometry.height; |
| 4973 | esurface->width = view->geometry.width * esurface->scale; |
| 4974 | esurface->height = view->geometry.height * esurface->scale; |
| 4975 | |
| 4976 | if (shell->exposay.focus_current == esurface->view) |
| 4977 | exposay_highlight_surface(shell, esurface); |
| 4978 | |
| 4979 | exposay_animate_in(esurface); |
| 4980 | |
| 4981 | i++; |
| 4982 | } |
| 4983 | |
| 4984 | weston_compositor_schedule_repaint(shell->compositor); |
| 4985 | |
| 4986 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 4987 | } |
| 4988 | |
| 4989 | static void |
| 4990 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time) |
| 4991 | { |
| 4992 | struct desktop_shell *shell = |
| 4993 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 4994 | |
| 4995 | exposay_pick(shell, |
| 4996 | wl_fixed_to_int(grab->pointer->x), |
| 4997 | wl_fixed_to_int(grab->pointer->y)); |
| 4998 | } |
| 4999 | |
| 5000 | static void |
| 5001 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5002 | uint32_t state_w) |
| 5003 | { |
| 5004 | struct desktop_shell *shell = |
| 5005 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5006 | struct weston_seat *seat = grab->pointer->seat; |
| 5007 | enum wl_pointer_button_state state = state_w; |
| 5008 | |
| 5009 | if (button != BTN_LEFT) |
| 5010 | return; |
| 5011 | |
| 5012 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5013 | * releasing on a different surface. */ |
| 5014 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5015 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5016 | return; |
| 5017 | } |
| 5018 | |
| 5019 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 5020 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5021 | else |
| 5022 | shell->exposay.clicked = NULL; |
| 5023 | } |
| 5024 | |
| 5025 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 5026 | noop_grab_focus, |
| 5027 | exposay_motion, |
| 5028 | exposay_button, |
| 5029 | }; |
| 5030 | |
| 5031 | static int |
| 5032 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 5033 | { |
| 5034 | struct exposay_surface *esurface; |
| 5035 | |
| 5036 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5037 | if (esurface->row != row || esurface->column != column) |
| 5038 | continue; |
| 5039 | |
| 5040 | exposay_highlight_surface(shell, esurface); |
| 5041 | return 1; |
| 5042 | } |
| 5043 | |
| 5044 | return 0; |
| 5045 | } |
| 5046 | |
| 5047 | static void |
| 5048 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 5049 | uint32_t state_w) |
| 5050 | { |
| 5051 | struct weston_seat *seat = grab->keyboard->seat; |
| 5052 | struct desktop_shell *shell = |
| 5053 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 5054 | enum wl_keyboard_key_state state = state_w; |
| 5055 | |
| 5056 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 5057 | return; |
| 5058 | |
| 5059 | switch (key) { |
| 5060 | case KEY_ESC: |
| 5061 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5062 | break; |
| 5063 | case KEY_ENTER: |
| 5064 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 5065 | break; |
| 5066 | case KEY_UP: |
| 5067 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 5068 | shell->exposay.column_current); |
| 5069 | break; |
| 5070 | case KEY_DOWN: |
| 5071 | /* Special case for trying to move to the bottom row when it |
| 5072 | * has fewer items than all the others. */ |
| 5073 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5074 | shell->exposay.column_current) && |
| 5075 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 5076 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 5077 | (shell->exposay.num_surfaces % |
| 5078 | shell->exposay.grid_size) - 1); |
| 5079 | } |
| 5080 | break; |
| 5081 | case KEY_LEFT: |
| 5082 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5083 | shell->exposay.column_current - 1); |
| 5084 | break; |
| 5085 | case KEY_RIGHT: |
| 5086 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 5087 | shell->exposay.column_current + 1); |
| 5088 | break; |
| 5089 | case KEY_TAB: |
| 5090 | /* Try to move right, then down (and to the leftmost column), |
| 5091 | * then if all else fails, to the top left. */ |
| 5092 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 5093 | shell->exposay.column_current + 1) && |
| 5094 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 5095 | exposay_maybe_move(shell, 0, 0); |
| 5096 | break; |
| 5097 | default: |
| 5098 | break; |
| 5099 | } |
| 5100 | } |
| 5101 | |
| 5102 | static void |
| 5103 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 5104 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5105 | uint32_t mods_locked, uint32_t group) |
| 5106 | { |
| 5107 | } |
| 5108 | |
| 5109 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 5110 | exposay_key, |
| 5111 | exposay_modifier, |
| 5112 | }; |
| 5113 | |
| 5114 | /** |
| 5115 | * Called when the transition from overview -> inactive has completed. |
| 5116 | */ |
| 5117 | static enum exposay_layout_state |
| 5118 | exposay_set_inactive(struct desktop_shell *shell) |
| 5119 | { |
| 5120 | struct weston_seat *seat = shell->exposay.seat; |
| 5121 | |
| 5122 | weston_keyboard_end_grab(seat->keyboard); |
| 5123 | weston_pointer_end_grab(seat->pointer); |
| 5124 | if (seat->keyboard->input_method_resource) |
| 5125 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 5126 | |
| 5127 | return EXPOSAY_LAYOUT_INACTIVE; |
| 5128 | } |
| 5129 | |
| 5130 | /** |
| 5131 | * Begins the transition from overview to inactive. */ |
| 5132 | static enum exposay_layout_state |
| 5133 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 5134 | { |
| 5135 | struct exposay_surface *esurface; |
| 5136 | |
| 5137 | /* Call activate() before we start the animations to avoid |
| 5138 | * animating back the old state and then immediately transitioning |
| 5139 | * to the new. */ |
| 5140 | if (switch_focus && shell->exposay.focus_current) |
| 5141 | activate(shell, shell->exposay.focus_current->surface, |
| 5142 | shell->exposay.seat); |
| 5143 | else if (shell->exposay.focus_prev) |
| 5144 | activate(shell, shell->exposay.focus_prev->surface, |
| 5145 | shell->exposay.seat); |
| 5146 | |
| 5147 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 5148 | exposay_animate_out(esurface); |
| 5149 | weston_compositor_schedule_repaint(shell->compositor); |
| 5150 | |
| 5151 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 5152 | } |
| 5153 | |
| 5154 | static enum exposay_layout_state |
| 5155 | exposay_transition_active(struct desktop_shell *shell) |
| 5156 | { |
| 5157 | struct weston_seat *seat = shell->exposay.seat; |
| 5158 | |
| 5159 | shell->exposay.workspace = get_current_workspace(shell); |
| 5160 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 5161 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 5162 | shell->exposay.clicked = NULL; |
| 5163 | wl_list_init(&shell->exposay.surface_list); |
| 5164 | |
| 5165 | lower_fullscreen_layer(shell); |
| 5166 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 5167 | weston_keyboard_start_grab(seat->keyboard, |
| 5168 | &shell->exposay.grab_kbd); |
| 5169 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 5170 | |
| 5171 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 5172 | weston_pointer_start_grab(seat->pointer, |
| 5173 | &shell->exposay.grab_ptr); |
| 5174 | weston_pointer_set_focus(seat->pointer, NULL, |
| 5175 | seat->pointer->x, seat->pointer->y); |
| 5176 | |
| 5177 | return exposay_layout(shell); |
| 5178 | } |
| 5179 | |
| 5180 | static void |
| 5181 | exposay_check_state(struct desktop_shell *shell) |
| 5182 | { |
| 5183 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 5184 | int do_switch = 0; |
| 5185 | |
| 5186 | /* Don't do anything whilst animations are running, just store up |
| 5187 | * target state changes and only act on them when the animations have |
| 5188 | * completed. */ |
| 5189 | if (exposay_is_animating(shell)) |
| 5190 | return; |
| 5191 | |
| 5192 | switch (shell->exposay.state_target) { |
| 5193 | case EXPOSAY_TARGET_OVERVIEW: |
| 5194 | switch (shell->exposay.state_cur) { |
| 5195 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 5196 | goto out; |
| 5197 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 5198 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 5199 | break; |
| 5200 | default: |
| 5201 | state_new = exposay_transition_active(shell); |
| 5202 | break; |
| 5203 | } |
| 5204 | break; |
| 5205 | |
| 5206 | case EXPOSAY_TARGET_SWITCH: |
| 5207 | do_switch = 1; /* fallthrough */ |
| 5208 | case EXPOSAY_TARGET_CANCEL: |
| 5209 | switch (shell->exposay.state_cur) { |
| 5210 | case EXPOSAY_LAYOUT_INACTIVE: |
| 5211 | goto out; |
| 5212 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 5213 | state_new = exposay_set_inactive(shell); |
| 5214 | break; |
| 5215 | default: |
| 5216 | state_new = exposay_transition_inactive(shell, do_switch); |
| 5217 | break; |
| 5218 | } |
| 5219 | |
| 5220 | break; |
| 5221 | } |
| 5222 | |
| 5223 | out: |
| 5224 | shell->exposay.state_cur = state_new; |
| 5225 | } |
| 5226 | |
| 5227 | static void |
| 5228 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 5229 | struct weston_seat *seat) |
| 5230 | { |
| 5231 | shell->exposay.state_target = state; |
| 5232 | shell->exposay.seat = seat; |
| 5233 | exposay_check_state(shell); |
| 5234 | } |
| 5235 | |
| 5236 | static void |
| 5237 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 5238 | void *data) |
| 5239 | { |
| 5240 | struct desktop_shell *shell = data; |
| 5241 | |
| 5242 | if (shell->exposay.state_target == EXPOSAY_TARGET_OVERVIEW) |
| 5243 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 5244 | else |
| 5245 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
| 5246 | } |
| 5247 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5248 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5249 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5250 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5251 | { |
| 5252 | struct weston_compositor *compositor = data; |
| 5253 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5254 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5255 | |
| 5256 | /* TODO: we're limiting to simple use cases, where we assume just |
| 5257 | * control on the primary display. We'd have to extend later if we |
| 5258 | * ever get support for setting backlights on random desktop LCD |
| 5259 | * panels though */ |
| 5260 | output = get_default_output(compositor); |
| 5261 | if (!output) |
| 5262 | return; |
| 5263 | |
| 5264 | if (!output->set_backlight) |
| 5265 | return; |
| 5266 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5267 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 5268 | backlight_new = output->backlight_current - 25; |
| 5269 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 5270 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5271 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 5272 | if (backlight_new < 5) |
| 5273 | backlight_new = 5; |
| 5274 | if (backlight_new > 255) |
| 5275 | backlight_new = 255; |
| 5276 | |
| 5277 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5278 | output->set_backlight(output, output->backlight_current); |
| 5279 | } |
| 5280 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5281 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5282 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5283 | struct weston_seat *seat; |
| 5284 | uint32_t key[2]; |
| 5285 | int key_released[2]; |
| 5286 | }; |
| 5287 | |
| 5288 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5289 | 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] | 5290 | uint32_t key, uint32_t state) |
| 5291 | { |
| 5292 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 5293 | struct weston_compositor *ec = db->seat->compositor; |
| 5294 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5295 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5296 | uint32_t serial; |
| 5297 | int send = 0, terminate = 0; |
| 5298 | int check_binding = 1; |
| 5299 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5300 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5301 | |
| 5302 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 5303 | /* Do not run bindings on key releases */ |
| 5304 | check_binding = 0; |
| 5305 | |
| 5306 | for (i = 0; i < 2; i++) |
| 5307 | if (key == db->key[i]) |
| 5308 | db->key_released[i] = 1; |
| 5309 | |
| 5310 | if (db->key_released[0] && db->key_released[1]) { |
| 5311 | /* All key releases been swalled so end the grab */ |
| 5312 | terminate = 1; |
| 5313 | } else if (key != db->key[0] && key != db->key[1]) { |
| 5314 | /* Should not swallow release of other keys */ |
| 5315 | send = 1; |
| 5316 | } |
| 5317 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 5318 | /* Do not check bindings for the first press of the binding |
| 5319 | * key. This allows it to be used as a debug shortcut. |
| 5320 | * We still need to swallow this event. */ |
| 5321 | check_binding = 0; |
| 5322 | } else if (db->key[1]) { |
| 5323 | /* If we already ran a binding don't process another one since |
| 5324 | * we can't keep track of all the binding keys that were |
| 5325 | * pressed in order to swallow the release events. */ |
| 5326 | send = 1; |
| 5327 | check_binding = 0; |
| 5328 | } |
| 5329 | |
| 5330 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5331 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 5332 | key, state)) { |
| 5333 | /* We ran a binding so swallow the press and keep the |
| 5334 | * grab to swallow the released too. */ |
| 5335 | send = 0; |
| 5336 | terminate = 0; |
| 5337 | db->key[1] = key; |
| 5338 | } else { |
| 5339 | /* Terminate the grab since the key pressed is not a |
| 5340 | * debug binding key. */ |
| 5341 | send = 1; |
| 5342 | terminate = 1; |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5347 | serial = wl_display_next_serial(display); |
| 5348 | resource_list = &grab->keyboard->focus_resource_list; |
| 5349 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5350 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 5351 | } |
| 5352 | } |
| 5353 | |
| 5354 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5355 | weston_keyboard_end_grab(grab->keyboard); |
| 5356 | if (grab->keyboard->input_method_resource) |
| 5357 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5358 | free(db); |
| 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5363 | 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] | 5364 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5365 | uint32_t mods_locked, uint32_t group) |
| 5366 | { |
| 5367 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5368 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5369 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5370 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5371 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 5372 | wl_resource_for_each(resource, resource_list) { |
| 5373 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 5374 | mods_latched, mods_locked, group); |
| 5375 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5376 | } |
| 5377 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5378 | static void |
| 5379 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 5380 | { |
| 5381 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 5382 | |
| 5383 | weston_keyboard_end_grab(grab->keyboard); |
| 5384 | free(db); |
| 5385 | } |
| 5386 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5387 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5388 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5389 | debug_binding_modifiers, |
| 5390 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5391 | }; |
| 5392 | |
| 5393 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5394 | 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] | 5395 | { |
| 5396 | struct debug_binding_grab *grab; |
| 5397 | |
| 5398 | grab = calloc(1, sizeof *grab); |
| 5399 | if (!grab) |
| 5400 | return; |
| 5401 | |
| 5402 | grab->seat = (struct weston_seat *) seat; |
| 5403 | grab->key[0] = key; |
| 5404 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5405 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5406 | } |
| 5407 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 5408 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5409 | 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] | 5410 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5411 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 5412 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5413 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5414 | struct desktop_shell *shell = data; |
| 5415 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5416 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5417 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 5418 | focus_surface = seat->keyboard->focus; |
| 5419 | if (!focus_surface) |
| 5420 | return; |
| 5421 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5422 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 5423 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5424 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 5425 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 5426 | |
| 5427 | /* Skip clients that we launched ourselves (the credentials of |
| 5428 | * the socketpair is ours) */ |
| 5429 | if (pid == getpid()) |
| 5430 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5431 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5432 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5436 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5437 | uint32_t key, void *data) |
| 5438 | { |
| 5439 | struct desktop_shell *shell = data; |
| 5440 | unsigned int new_index = shell->workspaces.current; |
| 5441 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5442 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5443 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5444 | if (new_index != 0) |
| 5445 | new_index--; |
| 5446 | |
| 5447 | change_workspace(shell, new_index); |
| 5448 | } |
| 5449 | |
| 5450 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5451 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5452 | uint32_t key, void *data) |
| 5453 | { |
| 5454 | struct desktop_shell *shell = data; |
| 5455 | unsigned int new_index = shell->workspaces.current; |
| 5456 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5457 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5458 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5459 | if (new_index < shell->workspaces.num - 1) |
| 5460 | new_index++; |
| 5461 | |
| 5462 | change_workspace(shell, new_index); |
| 5463 | } |
| 5464 | |
| 5465 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5466 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5467 | uint32_t key, void *data) |
| 5468 | { |
| 5469 | struct desktop_shell *shell = data; |
| 5470 | unsigned int new_index; |
| 5471 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 5472 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 5473 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5474 | new_index = key - KEY_F1; |
| 5475 | if (new_index >= shell->workspaces.num) |
| 5476 | new_index = shell->workspaces.num - 1; |
| 5477 | |
| 5478 | change_workspace(shell, new_index); |
| 5479 | } |
| 5480 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5481 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5482 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5483 | uint32_t key, void *data) |
| 5484 | { |
| 5485 | struct desktop_shell *shell = data; |
| 5486 | unsigned int new_index = shell->workspaces.current; |
| 5487 | |
| 5488 | if (shell->locked) |
| 5489 | return; |
| 5490 | |
| 5491 | if (new_index != 0) |
| 5492 | new_index--; |
| 5493 | |
| 5494 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5495 | } |
| 5496 | |
| 5497 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5498 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5499 | uint32_t key, void *data) |
| 5500 | { |
| 5501 | struct desktop_shell *shell = data; |
| 5502 | unsigned int new_index = shell->workspaces.current; |
| 5503 | |
| 5504 | if (shell->locked) |
| 5505 | return; |
| 5506 | |
| 5507 | if (new_index < shell->workspaces.num - 1) |
| 5508 | new_index++; |
| 5509 | |
| 5510 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 5511 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5512 | |
| 5513 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5514 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 5515 | { |
| 5516 | struct shell_output *output_listener = |
| 5517 | container_of(listener, struct shell_output, destroy_listener); |
| 5518 | |
| 5519 | wl_list_remove(&output_listener->destroy_listener.link); |
| 5520 | wl_list_remove(&output_listener->link); |
| 5521 | free(output_listener); |
| 5522 | } |
| 5523 | |
| 5524 | static void |
| 5525 | create_shell_output(struct desktop_shell *shell, |
| 5526 | struct weston_output *output) |
| 5527 | { |
| 5528 | struct shell_output *shell_output; |
| 5529 | |
| 5530 | shell_output = zalloc(sizeof *shell_output); |
| 5531 | if (shell_output == NULL) |
| 5532 | return; |
| 5533 | |
| 5534 | shell_output->output = output; |
| 5535 | shell_output->shell = shell; |
| 5536 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 5537 | wl_signal_add(&output->destroy_signal, |
| 5538 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 5539 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | static void |
| 5543 | handle_output_create(struct wl_listener *listener, void *data) |
| 5544 | { |
| 5545 | struct desktop_shell *shell = |
| 5546 | container_of(listener, struct desktop_shell, output_create_listener); |
| 5547 | struct weston_output *output = (struct weston_output *)data; |
| 5548 | |
| 5549 | create_shell_output(shell, output); |
| 5550 | } |
| 5551 | |
| 5552 | static void |
| 5553 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 5554 | struct desktop_shell *shell) |
| 5555 | { |
| 5556 | struct weston_output *output; |
| 5557 | |
| 5558 | wl_list_init(&shell->output_list); |
| 5559 | wl_list_for_each(output, &ec->output_list, link) |
| 5560 | create_shell_output(shell, output); |
| 5561 | |
| 5562 | shell->output_create_listener.notify = handle_output_create; |
| 5563 | wl_signal_add(&ec->output_created_signal, |
| 5564 | &shell->output_create_listener); |
| 5565 | } |
| 5566 | |
| 5567 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5568 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5569 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5570 | struct desktop_shell *shell = |
| 5571 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5572 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5573 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5574 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 5575 | if (shell->child.client) |
| 5576 | wl_client_destroy(shell->child.client); |
| 5577 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5578 | wl_list_remove(&shell->idle_listener.link); |
| 5579 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5580 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 5581 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 5582 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5583 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 5584 | wl_list_remove(&shell_output->destroy_listener.link); |
| 5585 | wl_list_remove(&shell_output->link); |
| 5586 | free(shell_output); |
| 5587 | } |
| 5588 | |
| 5589 | wl_list_remove(&shell->output_create_listener.link); |
| 5590 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5591 | wl_array_for_each(ws, &shell->workspaces.array) |
| 5592 | workspace_destroy(*ws); |
| 5593 | wl_array_release(&shell->workspaces.array); |
| 5594 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5595 | free(shell->screensaver.path); |
| 5596 | free(shell); |
| 5597 | } |
| 5598 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5599 | static void |
| 5600 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 5601 | { |
| 5602 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5603 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5604 | |
| 5605 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5606 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 5607 | MODIFIER_CTRL | MODIFIER_ALT, |
| 5608 | terminate_binding, ec); |
| 5609 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 5610 | click_to_activate_binding, |
| 5611 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5612 | weston_compositor_add_touch_binding(ec, 0, |
| 5613 | touch_to_activate_binding, |
| 5614 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5615 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5616 | MODIFIER_SUPER | MODIFIER_ALT, |
| 5617 | surface_opacity_binding, NULL); |
| 5618 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 5619 | MODIFIER_SUPER, zoom_axis_binding, |
| 5620 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5621 | |
| 5622 | /* configurable bindings */ |
| 5623 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5624 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 5625 | zoom_key_binding, NULL); |
| 5626 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 5627 | zoom_key_binding, NULL); |
| 5628 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 5629 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 5630 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5631 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 5632 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5633 | |
| 5634 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 5635 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 5636 | rotate_binding, NULL); |
| 5637 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5638 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 5639 | shell); |
| 5640 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 5641 | ec); |
| 5642 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 5643 | backlight_binding, ec); |
| 5644 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 5645 | ec); |
| 5646 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 5647 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5648 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 5649 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5650 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 5651 | workspace_up_binding, shell); |
| 5652 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 5653 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5654 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 5655 | workspace_move_surface_up_binding, |
| 5656 | shell); |
| 5657 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 5658 | workspace_move_surface_down_binding, |
| 5659 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5660 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame^] | 5661 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 5662 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5663 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 5664 | if (shell->workspaces.num > 1) { |
| 5665 | num_workspace_bindings = shell->workspaces.num; |
| 5666 | if (num_workspace_bindings > 6) |
| 5667 | num_workspace_bindings = 6; |
| 5668 | for (i = 0; i < num_workspace_bindings; i++) |
| 5669 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 5670 | workspace_f_binding, |
| 5671 | shell); |
| 5672 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5673 | |
| 5674 | /* Debug bindings */ |
| 5675 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 5676 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5677 | } |
| 5678 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5679 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5680 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5681 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5682 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5683 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5684 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5685 | struct workspace **pws; |
| 5686 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5687 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5688 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 5689 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5690 | if (shell == NULL) |
| 5691 | return -1; |
| 5692 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5693 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5694 | |
| 5695 | shell->destroy_listener.notify = shell_destroy; |
| 5696 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5697 | shell->idle_listener.notify = idle_handler; |
| 5698 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 5699 | shell->wake_listener.notify = wake_handler; |
| 5700 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5701 | shell->show_input_panel_listener.notify = show_input_panels; |
| 5702 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 5703 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 5704 | 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] | 5705 | shell->update_input_panel_listener.notify = update_input_panels; |
| 5706 | 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] | 5707 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 5708 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5709 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5710 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 5711 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 5712 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 5713 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5714 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 5715 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 5716 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 5717 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5718 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5719 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5720 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5721 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 5722 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5723 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 5724 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 5725 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5726 | |
| 5727 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5728 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 5729 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5730 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 5731 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame^] | 5732 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 5733 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 5734 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 5735 | for (i = 0; i < shell->workspaces.num; i++) { |
| 5736 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 5737 | if (pws == NULL) |
| 5738 | return -1; |
| 5739 | |
| 5740 | *pws = workspace_create(); |
| 5741 | if (*pws == NULL) |
| 5742 | return -1; |
| 5743 | } |
| 5744 | activate_workspace(shell, 0); |
| 5745 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 5746 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 5747 | wl_list_init(&shell->workspaces.animation.link); |
| 5748 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 5749 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5750 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5751 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5752 | return -1; |
| 5753 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5754 | if (wl_global_create(ec->wl_display, |
| 5755 | &desktop_shell_interface, 2, |
| 5756 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5757 | return -1; |
| 5758 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5759 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 5760 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5761 | return -1; |
| 5762 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5763 | 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] | 5764 | shell, bind_input_panel) == NULL) |
| 5765 | return -1; |
| 5766 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5767 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 5768 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 5769 | return -1; |
| 5770 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5771 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5772 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 5773 | setup_output_destroy_handler(ec, shell); |
| 5774 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5775 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5776 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5777 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5778 | shell->screensaver.timer = |
| 5779 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 5780 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 5781 | wl_list_for_each(seat, &ec->seat_list, link) |
| 5782 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 5783 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 5784 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5785 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5786 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5787 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 5788 | return 0; |
| 5789 | } |