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" |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 43 | #include "xdg-shell-server-protocol.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 44 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 45 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 46 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 47 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 48 | enum animation_type { |
| 49 | ANIMATION_NONE, |
| 50 | |
| 51 | ANIMATION_ZOOM, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 52 | ANIMATION_FADE, |
| 53 | ANIMATION_DIM_LAYER, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 54 | }; |
| 55 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 56 | enum fade_type { |
| 57 | FADE_IN, |
| 58 | FADE_OUT |
| 59 | }; |
| 60 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 61 | enum exposay_target_state { |
| 62 | EXPOSAY_TARGET_OVERVIEW, /* show all windows */ |
| 63 | EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */ |
| 64 | EXPOSAY_TARGET_SWITCH, /* return to normal, switch focus */ |
| 65 | }; |
| 66 | |
| 67 | enum exposay_layout_state { |
| 68 | EXPOSAY_LAYOUT_INACTIVE = 0, /* normal desktop */ |
| 69 | EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE, /* in transition to normal */ |
| 70 | EXPOSAY_LAYOUT_OVERVIEW, /* show all windows */ |
| 71 | EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW, /* in transition to all windows */ |
| 72 | }; |
| 73 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 74 | struct focus_state { |
| 75 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 76 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 77 | struct weston_surface *keyboard_focus; |
| 78 | struct wl_list link; |
| 79 | struct wl_listener seat_destroy_listener; |
| 80 | struct wl_listener surface_destroy_listener; |
| 81 | }; |
| 82 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 83 | struct focus_surface { |
| 84 | struct weston_surface *surface; |
| 85 | struct weston_view *view; |
| 86 | struct weston_transform workspace_transform; |
| 87 | }; |
| 88 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 89 | struct workspace { |
| 90 | struct weston_layer layer; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 91 | |
| 92 | struct wl_list focus_list; |
| 93 | struct wl_listener seat_destroyed_listener; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 94 | |
| 95 | struct focus_surface *fsurf_front; |
| 96 | struct focus_surface *fsurf_back; |
| 97 | struct weston_view_animation *focus_animation; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 100 | struct input_panel_surface { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 101 | struct wl_resource *resource; |
| 102 | struct wl_signal destroy_signal; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 103 | |
| 104 | struct desktop_shell *shell; |
| 105 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 106 | struct wl_list link; |
| 107 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 108 | struct weston_view *view; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 109 | struct wl_listener surface_destroy_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 110 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 111 | struct weston_output *output; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 112 | uint32_t panel; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 113 | }; |
| 114 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 115 | struct shell_output { |
| 116 | struct desktop_shell *shell; |
| 117 | struct weston_output *output; |
| 118 | struct wl_listener destroy_listener; |
| 119 | struct wl_list link; |
| 120 | }; |
| 121 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 122 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 123 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 124 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 125 | struct wl_listener idle_listener; |
| 126 | struct wl_listener wake_listener; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 127 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 128 | struct wl_listener show_input_panel_listener; |
| 129 | struct wl_listener hide_input_panel_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 130 | struct wl_listener update_input_panel_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 131 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 132 | struct weston_layer fullscreen_layer; |
| 133 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 134 | struct weston_layer background_layer; |
| 135 | struct weston_layer lock_layer; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 136 | struct weston_layer input_panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 137 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 138 | struct wl_listener pointer_focus_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 139 | struct weston_surface *grab_surface; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 140 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 141 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 142 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 143 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 144 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 145 | |
| 146 | unsigned deathcount; |
| 147 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 148 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 149 | |
| 150 | bool locked; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 151 | bool showing_input_panels; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 152 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 153 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 154 | struct { |
| 155 | struct weston_surface *surface; |
| 156 | pixman_box32_t cursor_rectangle; |
| 157 | } text_input; |
| 158 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 159 | struct weston_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 160 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 161 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 162 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 163 | struct wl_array array; |
| 164 | unsigned int current; |
| 165 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 166 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 167 | struct wl_list client_list; |
| 168 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 169 | struct weston_animation animation; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 170 | struct wl_list anim_sticky_list; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 171 | int anim_dir; |
| 172 | uint32_t anim_timestamp; |
| 173 | double anim_current; |
| 174 | struct workspace *anim_from; |
| 175 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 176 | } workspaces; |
| 177 | |
| 178 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 179 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 180 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 181 | struct wl_resource *binding; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 182 | struct weston_process process; |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 183 | struct wl_event_source *timer; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 184 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 185 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 186 | struct { |
| 187 | struct wl_resource *binding; |
| 188 | struct wl_list surfaces; |
| 189 | } input_panel; |
| 190 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 191 | struct { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 192 | struct weston_view *view; |
| 193 | struct weston_view_animation *animation; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 194 | enum fade_type type; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 195 | struct wl_event_source *startup_timer; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 196 | } fade; |
| 197 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 198 | struct exposay { |
| 199 | /* XXX: Make these exposay_surfaces. */ |
| 200 | struct weston_view *focus_prev; |
| 201 | struct weston_view *focus_current; |
| 202 | struct weston_view *clicked; |
| 203 | struct workspace *workspace; |
| 204 | struct weston_seat *seat; |
| 205 | struct wl_list surface_list; |
| 206 | |
| 207 | struct weston_keyboard_grab grab_kbd; |
| 208 | struct weston_pointer_grab grab_ptr; |
| 209 | |
| 210 | enum exposay_target_state state_target; |
| 211 | enum exposay_layout_state state_cur; |
| 212 | int in_flight; /* number of animations still running */ |
| 213 | |
| 214 | int num_surfaces; |
| 215 | int grid_size; |
| 216 | int surface_size; |
| 217 | |
| 218 | int hpadding_outer; |
| 219 | int vpadding_outer; |
| 220 | int padding_inner; |
| 221 | |
| 222 | int row_current; |
| 223 | int column_current; |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 224 | |
| 225 | bool mod_pressed; |
| 226 | bool mod_invalid; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 227 | } exposay; |
| 228 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 229 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 230 | enum animation_type win_animation_type; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 231 | enum animation_type startup_animation_type; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 232 | enum animation_type focus_animation_type; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 233 | |
| 234 | struct wl_listener output_create_listener; |
| 235 | struct wl_list output_list; |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 236 | |
| 237 | char *client; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 238 | }; |
| 239 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 240 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 241 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 242 | SHELL_SURFACE_TOPLEVEL, |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 243 | SHELL_SURFACE_POPUP, |
| 244 | SHELL_SURFACE_XWAYLAND |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 245 | }; |
| 246 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 247 | struct ping_timer { |
| 248 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 249 | uint32_t serial; |
| 250 | }; |
| 251 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 252 | /* |
| 253 | * Surface stacking and ordering. |
| 254 | * |
| 255 | * This is handled using several linked lists of surfaces, organised into |
| 256 | * ‘layers’. The layers are ordered, and each of the surfaces in one layer are |
| 257 | * above all of the surfaces in the layer below. The set of layers is static and |
| 258 | * in the following order (top-most first): |
| 259 | * • Lock layer (only ever displayed on its own) |
| 260 | * • Cursor layer |
| 261 | * • Fullscreen layer |
| 262 | * • Panel layer |
| 263 | * • Input panel layer |
| 264 | * • Workspace layers |
| 265 | * • Background layer |
| 266 | * |
| 267 | * The list of layers may be manipulated to remove whole layers of surfaces from |
| 268 | * display. For example, when locking the screen, all layers except the lock |
| 269 | * layer are removed. |
| 270 | * |
| 271 | * A surface’s layer is modified on configuring the surface, in |
| 272 | * set_surface_type() (which is only called when the surface’s type change is |
| 273 | * _committed_). If a surface’s type changes (e.g. when making a window |
| 274 | * fullscreen) its layer changes too. |
| 275 | * |
| 276 | * In order to allow popup and transient surfaces to be correctly stacked above |
| 277 | * their parent surfaces, each surface tracks both its parent surface, and a |
| 278 | * linked list of its children. When a surface’s layer is updated, so are the |
| 279 | * layers of its children. Note that child surfaces are *not* the same as |
| 280 | * subsurfaces — child/parent surfaces are purely for maintaining stacking |
| 281 | * order. |
| 282 | * |
| 283 | * The children_link list of siblings of a surface (i.e. those surfaces which |
| 284 | * have the same parent) only contains weston_surfaces which have a |
| 285 | * shell_surface. Stacking is not implemented for non-shell_surface |
| 286 | * weston_surfaces. This means that the following implication does *not* hold: |
| 287 | * (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link) |
| 288 | */ |
| 289 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 290 | struct shell_surface { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 291 | struct wl_resource *resource; |
| 292 | struct wl_signal destroy_signal; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 293 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 294 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 295 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 296 | int32_t last_width, last_height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 297 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 298 | struct weston_surface *parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 299 | struct wl_list children_list; /* child surfaces of this one */ |
| 300 | struct wl_list children_link; /* sibling surfaces of this one */ |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 301 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 302 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 303 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 304 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 305 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 306 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 307 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 308 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 309 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 310 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 311 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 312 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 313 | } rotation; |
| 314 | |
| 315 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 316 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 317 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 318 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 319 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 320 | } popup; |
| 321 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 322 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 323 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 324 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 325 | } transient; |
| 326 | |
| 327 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 328 | enum wl_shell_surface_fullscreen_method type; |
| 329 | struct weston_transform transform; /* matrix from x, y */ |
| 330 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 331 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 332 | } fullscreen; |
| 333 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 334 | struct ping_timer *ping_timer; |
| 335 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 336 | struct weston_transform workspace_transform; |
| 337 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 338 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 339 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 340 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 341 | |
| 342 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 343 | |
| 344 | struct { |
| 345 | bool maximized; |
| 346 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 347 | bool relative; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 348 | } state, next_state; /* surface states */ |
| 349 | bool state_changed; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 350 | }; |
| 351 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 352 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 353 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 354 | struct shell_surface *shsurf; |
| 355 | struct wl_listener shsurf_destroy_listener; |
| 356 | }; |
| 357 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 358 | struct shell_touch_grab { |
| 359 | struct weston_touch_grab grab; |
| 360 | struct shell_surface *shsurf; |
| 361 | struct wl_listener shsurf_destroy_listener; |
| 362 | struct weston_touch *touch; |
| 363 | }; |
| 364 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 365 | struct weston_move_grab { |
| 366 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 367 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 368 | }; |
| 369 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 370 | struct weston_touch_move_grab { |
| 371 | struct shell_touch_grab base; |
| 372 | wl_fixed_t dx, dy; |
| 373 | }; |
| 374 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 375 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 376 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 377 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 378 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 379 | float x; |
| 380 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 381 | } center; |
| 382 | }; |
| 383 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 384 | struct shell_seat { |
| 385 | struct weston_seat *seat; |
| 386 | struct wl_listener seat_destroy_listener; |
| 387 | |
| 388 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 389 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 390 | struct wl_list surfaces_list; |
| 391 | struct wl_client *client; |
| 392 | int32_t initial_up; |
| 393 | } popup_grab; |
| 394 | }; |
| 395 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 396 | static void |
| 397 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 398 | struct weston_seat *seat); |
| 399 | |
| 400 | static struct workspace * |
| 401 | get_current_workspace(struct desktop_shell *shell); |
| 402 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 403 | static struct shell_surface * |
| 404 | get_shell_surface(struct weston_surface *surface); |
| 405 | |
| 406 | static struct desktop_shell * |
| 407 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 408 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 409 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 410 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 411 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 412 | static void |
| 413 | shell_fade_startup(struct desktop_shell *shell); |
| 414 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 415 | static struct shell_seat * |
| 416 | get_shell_seat(struct weston_seat *seat); |
| 417 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 418 | static void |
| 419 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 420 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 421 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 422 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 423 | |
| 424 | static bool |
| 425 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 426 | |
| 427 | static bool |
| 428 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 429 | |
| 430 | static void |
| 431 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 432 | struct weston_surface *parent); |
| 433 | |
| 434 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 435 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 436 | { |
| 437 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 438 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 439 | |
| 440 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 441 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 442 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 443 | return false; |
| 444 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 445 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 446 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 447 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 448 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 449 | } |
| 450 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 451 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 452 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 453 | { |
| 454 | struct shell_grab *grab; |
| 455 | |
| 456 | grab = container_of(listener, struct shell_grab, |
| 457 | shsurf_destroy_listener); |
| 458 | |
| 459 | grab->shsurf = NULL; |
| 460 | } |
| 461 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 462 | static struct weston_view * |
| 463 | get_default_view(struct weston_surface *surface) |
| 464 | { |
| 465 | struct shell_surface *shsurf; |
| 466 | struct weston_view *view; |
| 467 | |
| 468 | if (!surface || wl_list_empty(&surface->views)) |
| 469 | return NULL; |
| 470 | |
| 471 | shsurf = get_shell_surface(surface); |
| 472 | if (shsurf) |
| 473 | return shsurf->view; |
| 474 | |
| 475 | wl_list_for_each(view, &surface->views, surface_link) |
| 476 | if (weston_view_is_mapped(view)) |
| 477 | return view; |
| 478 | |
| 479 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 480 | } |
| 481 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 482 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 483 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 484 | |
| 485 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 486 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 487 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 488 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 489 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 490 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 491 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 492 | struct desktop_shell *shell = shsurf->shell; |
| 493 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 494 | popup_grab_end(pointer); |
| 495 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 496 | grab->grab.interface = interface; |
| 497 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 498 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 499 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 500 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 501 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 502 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 503 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 504 | if (shell->child.desktop_shell) { |
| 505 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 506 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 507 | weston_pointer_set_focus(pointer, |
| 508 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 509 | wl_fixed_from_int(0), |
| 510 | wl_fixed_from_int(0)); |
| 511 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 515 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 516 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 517 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 518 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 519 | grab->shsurf->grabbed = 0; |
| 520 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 521 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 522 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 526 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 527 | const struct weston_touch_grab_interface *interface, |
| 528 | struct shell_surface *shsurf, |
| 529 | struct weston_touch *touch) |
| 530 | { |
| 531 | struct desktop_shell *shell = shsurf->shell; |
| 532 | |
| 533 | grab->grab.interface = interface; |
| 534 | grab->shsurf = shsurf; |
| 535 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 536 | wl_signal_add(&shsurf->destroy_signal, |
| 537 | &grab->shsurf_destroy_listener); |
| 538 | |
| 539 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 540 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 541 | |
| 542 | weston_touch_start_grab(touch, &grab->grab); |
| 543 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 544 | weston_touch_set_focus(touch->seat, |
| 545 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static void |
| 549 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 550 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 551 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 552 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 553 | grab->shsurf->grabbed = 0; |
| 554 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 555 | |
| 556 | weston_touch_end_grab(grab->touch); |
| 557 | } |
| 558 | |
| 559 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 560 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 561 | struct weston_output *output); |
| 562 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 563 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 564 | get_modifier(char *modifier) |
| 565 | { |
| 566 | if (!modifier) |
| 567 | return MODIFIER_SUPER; |
| 568 | |
| 569 | if (!strcmp("ctrl", modifier)) |
| 570 | return MODIFIER_CTRL; |
| 571 | else if (!strcmp("alt", modifier)) |
| 572 | return MODIFIER_ALT; |
| 573 | else if (!strcmp("super", modifier)) |
| 574 | return MODIFIER_SUPER; |
| 575 | else |
| 576 | return MODIFIER_SUPER; |
| 577 | } |
| 578 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 579 | static enum animation_type |
| 580 | get_animation_type(char *animation) |
| 581 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 582 | if (!strcmp("zoom", animation)) |
| 583 | return ANIMATION_ZOOM; |
| 584 | else if (!strcmp("fade", animation)) |
| 585 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 586 | else if (!strcmp("dim-layer", animation)) |
| 587 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 588 | else |
| 589 | return ANIMATION_NONE; |
| 590 | } |
| 591 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 592 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 593 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 594 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 595 | struct weston_config_section *section; |
| 596 | int duration; |
| 597 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 598 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 599 | section = weston_config_get_section(shell->compositor->config, |
| 600 | "screensaver", NULL, NULL); |
| 601 | weston_config_section_get_string(section, |
| 602 | "path", &shell->screensaver.path, NULL); |
| 603 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 604 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 605 | |
| 606 | section = weston_config_get_section(shell->compositor->config, |
| 607 | "shell", NULL, NULL); |
| 608 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 609 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 610 | shell->client = s; |
| 611 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 612 | "binding-modifier", &s, "super"); |
| 613 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 614 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 615 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 616 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 617 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 618 | weston_config_section_get_string(section, |
| 619 | "startup-animation", &s, "fade"); |
| 620 | shell->startup_animation_type = get_animation_type(s); |
| 621 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 622 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 623 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 624 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 625 | shell->focus_animation_type = get_animation_type(s); |
| 626 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 627 | weston_config_section_get_uint(section, "num-workspaces", |
| 628 | &shell->workspaces.num, |
| 629 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 630 | } |
| 631 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 632 | static struct weston_output * |
| 633 | get_default_output(struct weston_compositor *compositor) |
| 634 | { |
| 635 | return container_of(compositor->output_list.next, |
| 636 | struct weston_output, link); |
| 637 | } |
| 638 | |
| 639 | |
| 640 | /* no-op func for checking focus surface */ |
| 641 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 642 | focus_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 643 | { |
| 644 | } |
| 645 | |
| 646 | static struct focus_surface * |
| 647 | get_focus_surface(struct weston_surface *surface) |
| 648 | { |
| 649 | if (surface->configure == focus_surface_configure) |
| 650 | return surface->configure_private; |
| 651 | else |
| 652 | return NULL; |
| 653 | } |
| 654 | |
| 655 | static bool |
| 656 | is_focus_surface (struct weston_surface *es) |
| 657 | { |
| 658 | return (es->configure == focus_surface_configure); |
| 659 | } |
| 660 | |
| 661 | static bool |
| 662 | is_focus_view (struct weston_view *view) |
| 663 | { |
| 664 | return is_focus_surface (view->surface); |
| 665 | } |
| 666 | |
| 667 | static struct focus_surface * |
| 668 | create_focus_surface(struct weston_compositor *ec, |
| 669 | struct weston_output *output) |
| 670 | { |
| 671 | struct focus_surface *fsurf = NULL; |
| 672 | struct weston_surface *surface = NULL; |
| 673 | |
| 674 | fsurf = malloc(sizeof *fsurf); |
| 675 | if (!fsurf) |
| 676 | return NULL; |
| 677 | |
| 678 | fsurf->surface = weston_surface_create(ec); |
| 679 | surface = fsurf->surface; |
| 680 | if (surface == NULL) { |
| 681 | free(fsurf); |
| 682 | return NULL; |
| 683 | } |
| 684 | |
| 685 | surface->configure = focus_surface_configure; |
| 686 | surface->output = output; |
| 687 | surface->configure_private = fsurf; |
| 688 | |
| 689 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 690 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 691 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 692 | surface->width = output->width; |
| 693 | surface->height = output->height; |
| 694 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 695 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 696 | pixman_region32_fini(&surface->opaque); |
| 697 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 698 | output->width, output->height); |
| 699 | pixman_region32_fini(&surface->input); |
| 700 | pixman_region32_init(&surface->input); |
| 701 | |
| 702 | wl_list_init(&fsurf->workspace_transform.link); |
| 703 | |
| 704 | return fsurf; |
| 705 | } |
| 706 | |
| 707 | static void |
| 708 | focus_surface_destroy(struct focus_surface *fsurf) |
| 709 | { |
| 710 | weston_surface_destroy(fsurf->surface); |
| 711 | free(fsurf); |
| 712 | } |
| 713 | |
| 714 | static void |
| 715 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 716 | { |
| 717 | struct workspace *ws = data; |
| 718 | |
| 719 | ws->focus_animation = NULL; |
| 720 | } |
| 721 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 722 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 723 | focus_state_destroy(struct focus_state *state) |
| 724 | { |
| 725 | wl_list_remove(&state->seat_destroy_listener.link); |
| 726 | wl_list_remove(&state->surface_destroy_listener.link); |
| 727 | free(state); |
| 728 | } |
| 729 | |
| 730 | static void |
| 731 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 732 | { |
| 733 | struct focus_state *state = container_of(listener, |
| 734 | struct focus_state, |
| 735 | seat_destroy_listener); |
| 736 | |
| 737 | wl_list_remove(&state->link); |
| 738 | focus_state_destroy(state); |
| 739 | } |
| 740 | |
| 741 | static void |
| 742 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 743 | { |
| 744 | struct focus_state *state = container_of(listener, |
| 745 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 746 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 747 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 748 | struct weston_surface *main_surface, *next; |
| 749 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 750 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 751 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 752 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 753 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 754 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 755 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 756 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 757 | if (is_focus_view(view)) |
| 758 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 759 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 760 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 761 | break; |
| 762 | } |
| 763 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 764 | /* if the focus was a sub-surface, activate its main surface */ |
| 765 | if (main_surface != state->keyboard_focus) |
| 766 | next = main_surface; |
| 767 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 768 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 769 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 770 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 771 | activate(shell, next, state->seat); |
| 772 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 773 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 774 | if (state->ws->focus_animation) |
| 775 | weston_view_animation_destroy(state->ws->focus_animation); |
| 776 | |
| 777 | state->ws->focus_animation = weston_fade_run( |
| 778 | state->ws->fsurf_front->view, |
| 779 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 780 | focus_animation_done, state->ws); |
| 781 | } |
| 782 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 783 | wl_list_remove(&state->link); |
| 784 | focus_state_destroy(state); |
| 785 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 789 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 790 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 791 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 792 | |
| 793 | state = malloc(sizeof *state); |
| 794 | if (state == NULL) |
| 795 | return NULL; |
| 796 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 797 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 798 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 799 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 800 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 801 | |
| 802 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 803 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 804 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 805 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 806 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 807 | |
| 808 | return state; |
| 809 | } |
| 810 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 811 | static struct focus_state * |
| 812 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 813 | { |
| 814 | struct workspace *ws = get_current_workspace(shell); |
| 815 | struct focus_state *state; |
| 816 | |
| 817 | wl_list_for_each(state, &ws->focus_list, link) |
| 818 | if (state->seat == seat) |
| 819 | break; |
| 820 | |
| 821 | if (&state->link == &ws->focus_list) |
| 822 | state = focus_state_create(seat, ws); |
| 823 | |
| 824 | return state; |
| 825 | } |
| 826 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 827 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 828 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 829 | { |
| 830 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 831 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 832 | |
| 833 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 834 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 835 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 836 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
| 840 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 841 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 842 | struct weston_seat *seat) |
| 843 | { |
| 844 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 845 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 846 | |
| 847 | wl_list_for_each(state, &ws->focus_list, link) { |
| 848 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 849 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 850 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 851 | return; |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | static void |
| 857 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 858 | struct weston_surface *surface) |
| 859 | { |
| 860 | struct focus_state *state; |
| 861 | |
| 862 | wl_list_for_each(state, &ws->focus_list, link) |
| 863 | if (state->keyboard_focus == surface) |
| 864 | state->keyboard_focus = NULL; |
| 865 | } |
| 866 | |
| 867 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 868 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 869 | struct weston_view *from, struct weston_view *to) |
| 870 | { |
| 871 | struct weston_output *output; |
| 872 | bool focus_surface_created = false; |
| 873 | |
| 874 | /* FIXME: Only support dim animation using two layers */ |
| 875 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 876 | return; |
| 877 | |
| 878 | output = get_default_output(shell->compositor); |
| 879 | if (ws->fsurf_front == NULL && (from || to)) { |
| 880 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 881 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 882 | ws->fsurf_front->view->alpha = 0.0; |
| 883 | ws->fsurf_back->view->alpha = 0.0; |
| 884 | focus_surface_created = true; |
| 885 | } else { |
| 886 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 887 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 888 | } |
| 889 | |
| 890 | if (ws->focus_animation) { |
| 891 | weston_view_animation_destroy(ws->focus_animation); |
| 892 | ws->focus_animation = NULL; |
| 893 | } |
| 894 | |
| 895 | if (to) |
| 896 | wl_list_insert(&to->layer_link, |
| 897 | &ws->fsurf_front->view->layer_link); |
| 898 | else if (from) |
| 899 | wl_list_insert(&ws->layer.view_list, |
| 900 | &ws->fsurf_front->view->layer_link); |
| 901 | |
| 902 | if (focus_surface_created) { |
| 903 | ws->focus_animation = weston_fade_run( |
| 904 | ws->fsurf_front->view, |
| 905 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 906 | focus_animation_done, ws); |
| 907 | } else if (from) { |
| 908 | wl_list_insert(&from->layer_link, |
| 909 | &ws->fsurf_back->view->layer_link); |
| 910 | ws->focus_animation = weston_stable_fade_run( |
| 911 | ws->fsurf_front->view, 0.0, |
| 912 | ws->fsurf_back->view, 0.6, |
| 913 | focus_animation_done, ws); |
| 914 | } else if (to) { |
| 915 | wl_list_insert(&ws->layer.view_list, |
| 916 | &ws->fsurf_back->view->layer_link); |
| 917 | ws->focus_animation = weston_stable_fade_run( |
| 918 | ws->fsurf_front->view, 0.0, |
| 919 | ws->fsurf_back->view, 0.6, |
| 920 | focus_animation_done, ws); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 925 | workspace_destroy(struct workspace *ws) |
| 926 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 927 | struct focus_state *state, *next; |
| 928 | |
| 929 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 930 | focus_state_destroy(state); |
| 931 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 932 | if (ws->fsurf_front) |
| 933 | focus_surface_destroy(ws->fsurf_front); |
| 934 | if (ws->fsurf_back) |
| 935 | focus_surface_destroy(ws->fsurf_back); |
| 936 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 937 | free(ws); |
| 938 | } |
| 939 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 940 | static void |
| 941 | seat_destroyed(struct wl_listener *listener, void *data) |
| 942 | { |
| 943 | struct weston_seat *seat = data; |
| 944 | struct focus_state *state, *next; |
| 945 | struct workspace *ws = container_of(listener, |
| 946 | struct workspace, |
| 947 | seat_destroyed_listener); |
| 948 | |
| 949 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 950 | if (state->seat == seat) |
| 951 | wl_list_remove(&state->link); |
| 952 | } |
| 953 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 954 | static struct workspace * |
| 955 | workspace_create(void) |
| 956 | { |
| 957 | struct workspace *ws = malloc(sizeof *ws); |
| 958 | if (ws == NULL) |
| 959 | return NULL; |
| 960 | |
| 961 | weston_layer_init(&ws->layer, NULL); |
| 962 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 963 | wl_list_init(&ws->focus_list); |
| 964 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 965 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 966 | ws->fsurf_front = NULL; |
| 967 | ws->fsurf_back = NULL; |
| 968 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 969 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 970 | return ws; |
| 971 | } |
| 972 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 973 | static int |
| 974 | workspace_is_empty(struct workspace *ws) |
| 975 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 976 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 977 | } |
| 978 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 979 | static struct workspace * |
| 980 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 981 | { |
| 982 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 983 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 984 | pws += index; |
| 985 | return *pws; |
| 986 | } |
| 987 | |
| 988 | static struct workspace * |
| 989 | get_current_workspace(struct desktop_shell *shell) |
| 990 | { |
| 991 | return get_workspace(shell, shell->workspaces.current); |
| 992 | } |
| 993 | |
| 994 | static void |
| 995 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 996 | { |
| 997 | struct workspace *ws; |
| 998 | |
| 999 | ws = get_workspace(shell, index); |
| 1000 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1001 | |
| 1002 | shell->workspaces.current = index; |
| 1003 | } |
| 1004 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1005 | static unsigned int |
| 1006 | get_output_height(struct weston_output *output) |
| 1007 | { |
| 1008 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1009 | } |
| 1010 | |
| 1011 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1012 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1013 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1014 | struct weston_transform *transform; |
| 1015 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1016 | if (is_focus_view(view)) { |
| 1017 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1018 | transform = &fsurf->workspace_transform; |
| 1019 | } else { |
| 1020 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1021 | transform = &shsurf->workspace_transform; |
| 1022 | } |
| 1023 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1024 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1025 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1026 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1027 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1028 | weston_matrix_init(&transform->matrix); |
| 1029 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1030 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1031 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | static void |
| 1035 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1036 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1037 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1038 | unsigned int height; |
| 1039 | double d; |
| 1040 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1041 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1042 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1043 | d = height * fraction; |
| 1044 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1045 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | static void |
| 1050 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1051 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1052 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1053 | unsigned int height; |
| 1054 | double d; |
| 1055 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1056 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1057 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1058 | |
| 1059 | if (fraction > 0) |
| 1060 | d = -(height - height * fraction); |
| 1061 | else |
| 1062 | d = height + height * fraction; |
| 1063 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1064 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1069 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1070 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1071 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1072 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1073 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1074 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1075 | shell->workspaces.current, |
| 1076 | shell->workspaces.num); |
| 1077 | } |
| 1078 | |
| 1079 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1080 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1081 | unsigned int index, |
| 1082 | struct workspace *from, |
| 1083 | struct workspace *to) |
| 1084 | { |
| 1085 | shell->workspaces.current = index; |
| 1086 | |
| 1087 | shell->workspaces.anim_to = to; |
| 1088 | shell->workspaces.anim_from = from; |
| 1089 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1090 | shell->workspaces.anim_timestamp = 0; |
| 1091 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1092 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static void |
| 1096 | workspace_deactivate_transforms(struct workspace *ws) |
| 1097 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1098 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1099 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1100 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1101 | 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] | 1102 | if (is_focus_view(view)) { |
| 1103 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1104 | transform = &fsurf->workspace_transform; |
| 1105 | } else { |
| 1106 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1107 | transform = &shsurf->workspace_transform; |
| 1108 | } |
| 1109 | |
| 1110 | if (!wl_list_empty(&transform->link)) { |
| 1111 | wl_list_remove(&transform->link); |
| 1112 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1113 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1114 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | static void |
| 1119 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1120 | struct workspace *from, |
| 1121 | struct workspace *to) |
| 1122 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1123 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1124 | |
| 1125 | wl_list_remove(&shell->workspaces.animation.link); |
| 1126 | workspace_deactivate_transforms(from); |
| 1127 | workspace_deactivate_transforms(to); |
| 1128 | shell->workspaces.anim_to = NULL; |
| 1129 | |
| 1130 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1131 | } |
| 1132 | |
| 1133 | static void |
| 1134 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1135 | struct weston_output *output, uint32_t msecs) |
| 1136 | { |
| 1137 | struct desktop_shell *shell = |
| 1138 | container_of(animation, struct desktop_shell, |
| 1139 | workspaces.animation); |
| 1140 | struct workspace *from = shell->workspaces.anim_from; |
| 1141 | struct workspace *to = shell->workspaces.anim_to; |
| 1142 | uint32_t t; |
| 1143 | double x, y; |
| 1144 | |
| 1145 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1146 | finish_workspace_change_animation(shell, from, to); |
| 1147 | return; |
| 1148 | } |
| 1149 | |
| 1150 | if (shell->workspaces.anim_timestamp == 0) { |
| 1151 | if (shell->workspaces.anim_current == 0.0) |
| 1152 | shell->workspaces.anim_timestamp = msecs; |
| 1153 | else |
| 1154 | shell->workspaces.anim_timestamp = |
| 1155 | msecs - |
| 1156 | /* Invers of movement function 'y' below. */ |
| 1157 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1158 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1159 | M_2_PI); |
| 1160 | } |
| 1161 | |
| 1162 | t = msecs - shell->workspaces.anim_timestamp; |
| 1163 | |
| 1164 | /* |
| 1165 | * x = [0, π/2] |
| 1166 | * y(x) = sin(x) |
| 1167 | */ |
| 1168 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1169 | y = sin(x); |
| 1170 | |
| 1171 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1172 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1173 | |
| 1174 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1175 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1176 | shell->workspaces.anim_current = y; |
| 1177 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1178 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1179 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1180 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1181 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static void |
| 1185 | animate_workspace_change(struct desktop_shell *shell, |
| 1186 | unsigned int index, |
| 1187 | struct workspace *from, |
| 1188 | struct workspace *to) |
| 1189 | { |
| 1190 | struct weston_output *output; |
| 1191 | |
| 1192 | int dir; |
| 1193 | |
| 1194 | if (index > shell->workspaces.current) |
| 1195 | dir = -1; |
| 1196 | else |
| 1197 | dir = 1; |
| 1198 | |
| 1199 | shell->workspaces.current = index; |
| 1200 | |
| 1201 | shell->workspaces.anim_dir = dir; |
| 1202 | shell->workspaces.anim_from = from; |
| 1203 | shell->workspaces.anim_to = to; |
| 1204 | shell->workspaces.anim_current = 0.0; |
| 1205 | shell->workspaces.anim_timestamp = 0; |
| 1206 | |
| 1207 | output = container_of(shell->compositor->output_list.next, |
| 1208 | struct weston_output, link); |
| 1209 | wl_list_insert(&output->animation_list, |
| 1210 | &shell->workspaces.animation.link); |
| 1211 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1212 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1213 | |
| 1214 | workspace_translate_in(to, 0); |
| 1215 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1216 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1217 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1218 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1219 | } |
| 1220 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1221 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1222 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1223 | struct workspace *from, struct workspace *to) |
| 1224 | { |
| 1225 | shell->workspaces.current = index; |
| 1226 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1227 | wl_list_remove(&from->layer.link); |
| 1228 | } |
| 1229 | |
| 1230 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1231 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1232 | { |
| 1233 | struct workspace *from; |
| 1234 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1235 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1236 | |
| 1237 | if (index == shell->workspaces.current) |
| 1238 | return; |
| 1239 | |
| 1240 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1241 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1242 | return; |
| 1243 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1244 | from = get_current_workspace(shell); |
| 1245 | to = get_workspace(shell, index); |
| 1246 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1247 | if (shell->workspaces.anim_from == to && |
| 1248 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1249 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1250 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1251 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1252 | return; |
| 1253 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1254 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1255 | if (shell->workspaces.anim_to != NULL) |
| 1256 | finish_workspace_change_animation(shell, |
| 1257 | shell->workspaces.anim_from, |
| 1258 | shell->workspaces.anim_to); |
| 1259 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1260 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1261 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1262 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1263 | wl_list_for_each(state, &from->focus_list, link) |
| 1264 | if (state->keyboard_focus) |
| 1265 | animate_focus_change(shell, from, |
| 1266 | get_default_view(state->keyboard_focus), NULL); |
| 1267 | |
| 1268 | wl_list_for_each(state, &to->focus_list, link) |
| 1269 | if (state->keyboard_focus) |
| 1270 | animate_focus_change(shell, to, |
| 1271 | NULL, get_default_view(state->keyboard_focus)); |
| 1272 | } |
| 1273 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1274 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1275 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1276 | else |
| 1277 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1278 | |
| 1279 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1280 | } |
| 1281 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1282 | static bool |
| 1283 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1284 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1285 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1286 | struct wl_list *e; |
| 1287 | |
| 1288 | if (wl_list_empty(list)) |
| 1289 | return false; |
| 1290 | |
| 1291 | e = list->next; |
| 1292 | |
| 1293 | if (e->next != list) |
| 1294 | return false; |
| 1295 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1296 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1300 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1301 | struct shell_surface *shsurf, |
| 1302 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1303 | { |
| 1304 | struct workspace *from; |
| 1305 | struct workspace *to; |
| 1306 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1307 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1308 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1309 | |
| 1310 | if (workspace == shell->workspaces.current) |
| 1311 | return; |
| 1312 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1313 | view = get_default_view(shsurf->surface); |
| 1314 | if (!view) |
| 1315 | return; |
| 1316 | |
| 1317 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1318 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1319 | if (workspace >= shell->workspaces.num) |
| 1320 | workspace = shell->workspaces.num - 1; |
| 1321 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1322 | from = get_current_workspace(shell); |
| 1323 | to = get_workspace(shell, workspace); |
| 1324 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1325 | wl_list_remove(&view->layer_link); |
| 1326 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1327 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1328 | shell_surface_update_child_surface_layers(shsurf); |
| 1329 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1330 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1331 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1332 | if (!seat->keyboard) |
| 1333 | continue; |
| 1334 | |
| 1335 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1336 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1337 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1338 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1339 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1340 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1344 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1345 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1346 | unsigned int index) |
| 1347 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1348 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1349 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1350 | struct shell_surface *shsurf; |
| 1351 | struct workspace *from; |
| 1352 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1353 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1354 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1355 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1356 | view = get_default_view(surface); |
| 1357 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1358 | index == shell->workspaces.current || |
| 1359 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1360 | return; |
| 1361 | |
| 1362 | from = get_current_workspace(shell); |
| 1363 | to = get_workspace(shell, index); |
| 1364 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1365 | wl_list_remove(&view->layer_link); |
| 1366 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1367 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1368 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1369 | if (shsurf != NULL) |
| 1370 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1371 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1372 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1373 | drop_focus_state(shell, from, surface); |
| 1374 | |
| 1375 | if (shell->workspaces.anim_from == to && |
| 1376 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1377 | wl_list_remove(&to->layer.link); |
| 1378 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1379 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1380 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1381 | broadcast_current_workspace_state(shell); |
| 1382 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1383 | return; |
| 1384 | } |
| 1385 | |
| 1386 | if (shell->workspaces.anim_to != NULL) |
| 1387 | finish_workspace_change_animation(shell, |
| 1388 | shell->workspaces.anim_from, |
| 1389 | shell->workspaces.anim_to); |
| 1390 | |
| 1391 | if (workspace_is_empty(from) && |
| 1392 | workspace_has_only(to, surface)) |
| 1393 | update_workspace(shell, index, from, to); |
| 1394 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1395 | if (shsurf != NULL && |
| 1396 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1397 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1398 | &shsurf->workspace_transform.link); |
| 1399 | |
| 1400 | animate_workspace_change(shell, index, from, to); |
| 1401 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1402 | |
| 1403 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1404 | |
| 1405 | state = ensure_focus_state(shell, seat); |
| 1406 | if (state != NULL) |
| 1407 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | static void |
| 1411 | workspace_manager_move_surface(struct wl_client *client, |
| 1412 | struct wl_resource *resource, |
| 1413 | struct wl_resource *surface_resource, |
| 1414 | uint32_t workspace) |
| 1415 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1416 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1417 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1418 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1419 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1420 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1421 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1422 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1423 | shell_surface = get_shell_surface(main_surface); |
| 1424 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1425 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1426 | |
| 1427 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1431 | workspace_manager_move_surface, |
| 1432 | }; |
| 1433 | |
| 1434 | static void |
| 1435 | unbind_resource(struct wl_resource *resource) |
| 1436 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1437 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | static void |
| 1441 | bind_workspace_manager(struct wl_client *client, |
| 1442 | void *data, uint32_t version, uint32_t id) |
| 1443 | { |
| 1444 | struct desktop_shell *shell = data; |
| 1445 | struct wl_resource *resource; |
| 1446 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1447 | resource = wl_resource_create(client, |
| 1448 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1449 | |
| 1450 | if (resource == NULL) { |
| 1451 | weston_log("couldn't add workspace manager object"); |
| 1452 | return; |
| 1453 | } |
| 1454 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1455 | wl_resource_set_implementation(resource, |
| 1456 | &workspace_manager_implementation, |
| 1457 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1458 | wl_list_insert(&shell->workspaces.client_list, |
| 1459 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1460 | |
| 1461 | workspace_manager_send_state(resource, |
| 1462 | shell->workspaces.current, |
| 1463 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1464 | } |
| 1465 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1466 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1467 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1468 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1469 | { |
| 1470 | } |
| 1471 | |
| 1472 | static void |
| 1473 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1474 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1475 | struct weston_touch_move_grab *move = |
| 1476 | (struct weston_touch_move_grab *) container_of( |
| 1477 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1478 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1479 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1480 | shell_touch_grab_end(&move->base); |
| 1481 | free(move); |
| 1482 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | static void |
| 1486 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1487 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1488 | { |
| 1489 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1490 | struct shell_surface *shsurf = move->base.shsurf; |
| 1491 | struct weston_surface *es; |
| 1492 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1493 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1494 | |
| 1495 | if (!shsurf) |
| 1496 | return; |
| 1497 | |
| 1498 | es = shsurf->surface; |
| 1499 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1500 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1501 | |
| 1502 | weston_compositor_schedule_repaint(es->compositor); |
| 1503 | } |
| 1504 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1505 | static void |
| 1506 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1507 | { |
| 1508 | struct weston_touch_move_grab *move = |
| 1509 | (struct weston_touch_move_grab *) container_of( |
| 1510 | grab, struct shell_touch_grab, grab); |
| 1511 | |
| 1512 | shell_touch_grab_end(&move->base); |
| 1513 | free(move); |
| 1514 | } |
| 1515 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1516 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1517 | touch_move_grab_down, |
| 1518 | touch_move_grab_up, |
| 1519 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1520 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1521 | }; |
| 1522 | |
| 1523 | static int |
| 1524 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1525 | { |
| 1526 | struct weston_touch_move_grab *move; |
| 1527 | |
| 1528 | if (!shsurf) |
| 1529 | return -1; |
| 1530 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1531 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1532 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1533 | if (shsurf->grabbed) |
| 1534 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1535 | |
| 1536 | move = malloc(sizeof *move); |
| 1537 | if (!move) |
| 1538 | return -1; |
| 1539 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1540 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1541 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1542 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1543 | seat->touch->grab_y; |
| 1544 | |
| 1545 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1546 | seat->touch); |
| 1547 | |
| 1548 | return 0; |
| 1549 | } |
| 1550 | |
| 1551 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1552 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1553 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1557 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1558 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1559 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1560 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1561 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1562 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1563 | int dx, dy; |
| 1564 | |
| 1565 | weston_pointer_move(pointer, x, y); |
| 1566 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1567 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1568 | |
| 1569 | if (!shsurf) |
| 1570 | return; |
| 1571 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1572 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1573 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1574 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1578 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1579 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1580 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1581 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1582 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1583 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1584 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1585 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1586 | if (pointer->button_count == 0 && |
| 1587 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1588 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1589 | free(grab); |
| 1590 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1591 | } |
| 1592 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1593 | static void |
| 1594 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1595 | { |
| 1596 | struct shell_grab *shell_grab = |
| 1597 | container_of(grab, struct shell_grab, grab); |
| 1598 | |
| 1599 | shell_grab_end(shell_grab); |
| 1600 | free(grab); |
| 1601 | } |
| 1602 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1603 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1604 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1605 | move_grab_motion, |
| 1606 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1607 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1608 | }; |
| 1609 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1610 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1611 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1612 | { |
| 1613 | struct weston_move_grab *move; |
| 1614 | |
| 1615 | if (!shsurf) |
| 1616 | return -1; |
| 1617 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1618 | if (shsurf->grabbed) |
| 1619 | return 0; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1620 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1621 | return 0; |
| 1622 | |
| 1623 | move = malloc(sizeof *move); |
| 1624 | if (!move) |
| 1625 | return -1; |
| 1626 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1627 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1628 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1629 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1630 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1631 | |
| 1632 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1633 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1634 | |
| 1635 | return 0; |
| 1636 | } |
| 1637 | |
| 1638 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 1639 | common_surface_move(struct wl_resource *resource, |
| 1640 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1641 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1642 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1643 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1644 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1645 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1646 | if (seat->pointer && |
| 1647 | seat->pointer->button_count > 0 && |
| 1648 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1649 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1650 | if ((surface == shsurf->surface) && |
| 1651 | (surface_move(shsurf, seat) < 0)) |
| 1652 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1653 | } else if (seat->touch && |
| 1654 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1655 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1656 | if ((surface == shsurf->surface) && |
| 1657 | (surface_touch_move(shsurf, seat) < 0)) |
| 1658 | wl_resource_post_no_memory(resource); |
| 1659 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 1662 | static void |
| 1663 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1664 | struct wl_resource *seat_resource, uint32_t serial) |
| 1665 | { |
| 1666 | common_surface_move(resource, seat_resource, serial); |
| 1667 | } |
| 1668 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1669 | struct weston_resize_grab { |
| 1670 | struct shell_grab base; |
| 1671 | uint32_t edges; |
| 1672 | int32_t width, height; |
| 1673 | }; |
| 1674 | |
| 1675 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1676 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1677 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1678 | { |
| 1679 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1680 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1681 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1682 | int32_t width, height; |
| 1683 | wl_fixed_t from_x, from_y; |
| 1684 | wl_fixed_t to_x, to_y; |
| 1685 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1686 | weston_pointer_move(pointer, x, y); |
| 1687 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1688 | if (!shsurf) |
| 1689 | return; |
| 1690 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1691 | weston_view_from_global_fixed(shsurf->view, |
| 1692 | pointer->grab_x, pointer->grab_y, |
| 1693 | &from_x, &from_y); |
| 1694 | weston_view_from_global_fixed(shsurf->view, |
| 1695 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1696 | |
| 1697 | width = resize->width; |
| 1698 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1699 | width += wl_fixed_to_int(from_x - to_x); |
| 1700 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1701 | width += wl_fixed_to_int(to_x - from_x); |
| 1702 | } |
| 1703 | |
| 1704 | height = resize->height; |
| 1705 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1706 | height += wl_fixed_to_int(from_y - to_y); |
| 1707 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1708 | height += wl_fixed_to_int(to_y - from_y); |
| 1709 | } |
| 1710 | |
| 1711 | shsurf->client->send_configure(shsurf->surface, |
| 1712 | resize->edges, width, height); |
| 1713 | } |
| 1714 | |
| 1715 | static void |
| 1716 | send_configure(struct weston_surface *surface, |
| 1717 | uint32_t edges, int32_t width, int32_t height) |
| 1718 | { |
| 1719 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1720 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1721 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1722 | edges, width, height); |
| 1723 | } |
| 1724 | |
| 1725 | static const struct weston_shell_client shell_client = { |
| 1726 | send_configure |
| 1727 | }; |
| 1728 | |
| 1729 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1730 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1731 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1732 | { |
| 1733 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1734 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1735 | enum wl_pointer_button_state state = state_w; |
| 1736 | |
| 1737 | if (pointer->button_count == 0 && |
| 1738 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1739 | shell_grab_end(&resize->base); |
| 1740 | free(grab); |
| 1741 | } |
| 1742 | } |
| 1743 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1744 | static void |
| 1745 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1746 | { |
| 1747 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1748 | |
| 1749 | shell_grab_end(&resize->base); |
| 1750 | free(grab); |
| 1751 | } |
| 1752 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1753 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1754 | noop_grab_focus, |
| 1755 | resize_grab_motion, |
| 1756 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1757 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1758 | }; |
| 1759 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1760 | /* |
| 1761 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1762 | * in the surface coordinates system. */ |
| 1763 | static void |
| 1764 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1765 | int32_t *y, int32_t *w, int32_t *h) { |
| 1766 | pixman_region32_t region; |
| 1767 | pixman_box32_t *box; |
| 1768 | struct weston_subsurface *subsurface; |
| 1769 | |
| 1770 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1771 | surface->width, |
| 1772 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1773 | |
| 1774 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1775 | pixman_region32_union_rect(®ion, ®ion, |
| 1776 | subsurface->position.x, |
| 1777 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1778 | subsurface->surface->width, |
| 1779 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | box = pixman_region32_extents(®ion); |
| 1783 | if (x) |
| 1784 | *x = box->x1; |
| 1785 | if (y) |
| 1786 | *y = box->y1; |
| 1787 | if (w) |
| 1788 | *w = box->x2 - box->x1; |
| 1789 | if (h) |
| 1790 | *h = box->y2 - box->y1; |
| 1791 | |
| 1792 | pixman_region32_fini(®ion); |
| 1793 | } |
| 1794 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1795 | static int |
| 1796 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1797 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1798 | { |
| 1799 | struct weston_resize_grab *resize; |
| 1800 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1801 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1802 | return 0; |
| 1803 | |
| 1804 | if (edges == 0 || edges > 15 || |
| 1805 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1806 | return 0; |
| 1807 | |
| 1808 | resize = malloc(sizeof *resize); |
| 1809 | if (!resize) |
| 1810 | return -1; |
| 1811 | |
| 1812 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1813 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1814 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1815 | |
| 1816 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1817 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1818 | |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 1823 | common_surface_resize(struct wl_resource *resource, |
| 1824 | struct wl_resource *seat_resource, uint32_t serial, |
| 1825 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1826 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1827 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1828 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1829 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1830 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1831 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1832 | return; |
| 1833 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1834 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1835 | if (seat->pointer->button_count == 0 || |
| 1836 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1837 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1838 | return; |
| 1839 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1840 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1841 | wl_resource_post_no_memory(resource); |
| 1842 | } |
| 1843 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1844 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 1845 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1846 | struct wl_resource *seat_resource, uint32_t serial, |
| 1847 | uint32_t edges) |
| 1848 | { |
| 1849 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1850 | } |
| 1851 | |
| 1852 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1853 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1854 | |
| 1855 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1856 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1857 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1858 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1859 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1860 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1861 | wl_fixed_t sx, sy; |
| 1862 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1863 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1864 | pointer->x, pointer->y, |
| 1865 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1866 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1867 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1868 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1872 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1873 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1874 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1875 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1876 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1877 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1878 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1879 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1880 | uint32_t time, uint32_t button, uint32_t state) |
| 1881 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1882 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1883 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1884 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1885 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1886 | if (shsurf && button == BTN_LEFT && state) { |
| 1887 | activate(shsurf->shell, shsurf->surface, seat); |
| 1888 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1889 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1890 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1891 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1892 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1893 | } |
| 1894 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1895 | static void |
| 1896 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1897 | { |
| 1898 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1899 | |
| 1900 | shell_grab_end(grab); |
| 1901 | free(grab); |
| 1902 | } |
| 1903 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1904 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1905 | busy_cursor_grab_focus, |
| 1906 | busy_cursor_grab_motion, |
| 1907 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1908 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1909 | }; |
| 1910 | |
| 1911 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1912 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1913 | { |
| 1914 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1915 | |
| 1916 | grab = malloc(sizeof *grab); |
| 1917 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1918 | return; |
| 1919 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1920 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1921 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1922 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1923 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1924 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1925 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1926 | { |
| 1927 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1928 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1929 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1930 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1931 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1932 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1933 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1934 | } |
| 1935 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1936 | static void |
| 1937 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1938 | { |
| 1939 | if (!shsurf || !shsurf->ping_timer) |
| 1940 | return; |
| 1941 | |
| 1942 | if (shsurf->ping_timer->source) |
| 1943 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1944 | |
| 1945 | free(shsurf->ping_timer); |
| 1946 | shsurf->ping_timer = NULL; |
| 1947 | } |
| 1948 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1949 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1950 | ping_timeout_handler(void *data) |
| 1951 | { |
| 1952 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1953 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1954 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1955 | /* Client is not responding */ |
| 1956 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1957 | |
| 1958 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1959 | if (seat->pointer->focus && |
| 1960 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1961 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1962 | |
| 1963 | return 1; |
| 1964 | } |
| 1965 | |
| 1966 | static void |
| 1967 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1968 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1969 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1970 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1971 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1972 | |
| 1973 | if (!shsurf) |
| 1974 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1975 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1976 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1977 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1978 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1979 | return; |
| 1980 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1981 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1982 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1983 | if (!shsurf->ping_timer) |
| 1984 | return; |
| 1985 | |
| 1986 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1987 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1988 | shsurf->ping_timer->source = |
| 1989 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1990 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1991 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 1992 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1993 | wl_shell_surface_send_ping(shsurf->resource, serial); |
| 1994 | else if (shell_surface_is_xdg_surface(shsurf)) |
| 1995 | xdg_surface_send_ping(shsurf->resource, serial); |
| 1996 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 1997 | xdg_popup_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1998 | } |
| 1999 | } |
| 2000 | |
| 2001 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2002 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2003 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2004 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2005 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2006 | struct weston_compositor *compositor; |
| 2007 | struct shell_surface *shsurf; |
| 2008 | uint32_t serial; |
| 2009 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2010 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2011 | return; |
| 2012 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2013 | compositor = view->surface->compositor; |
| 2014 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2015 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 2016 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2017 | set_busy_cursor(shsurf, pointer); |
| 2018 | } else { |
| 2019 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2020 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 2025 | create_pointer_focus_listener(struct weston_seat *seat) |
| 2026 | { |
| 2027 | struct wl_listener *listener; |
| 2028 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2029 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 2030 | return; |
| 2031 | |
| 2032 | listener = malloc(sizeof *listener); |
| 2033 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2034 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 2038 | xdg_surface_set_transient_for(struct wl_client *client, |
| 2039 | struct wl_resource *resource, |
| 2040 | struct wl_resource *parent_resource) |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2041 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2042 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 2043 | struct weston_surface *parent = |
| 2044 | wl_resource_get_user_data(parent_resource); |
| 2045 | |
| 2046 | shell_surface_set_parent(shsurf, parent); |
| 2047 | } |
| 2048 | |
| 2049 | static void |
| 2050 | surface_pong(struct shell_surface *shsurf, uint32_t serial) |
| 2051 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2052 | struct weston_compositor *ec = shsurf->surface->compositor; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 2053 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2054 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 2055 | if (shsurf->ping_timer == NULL) |
| 2056 | /* Just ignore unsolicited pong. */ |
| 2057 | return; |
| 2058 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2059 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2060 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 2061 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 2062 | if(seat->pointer) |
| 2063 | end_busy_cursor(shsurf, seat->pointer); |
| 2064 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2065 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2066 | } |
| 2067 | } |
| 2068 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2069 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 2070 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 2071 | uint32_t serial) |
| 2072 | { |
| 2073 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2074 | |
| 2075 | surface_pong(shsurf, serial); |
| 2076 | |
| 2077 | } |
| 2078 | |
| 2079 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2080 | set_title(struct shell_surface *shsurf, const char *title) |
| 2081 | { |
| 2082 | free(shsurf->title); |
| 2083 | shsurf->title = strdup(title); |
| 2084 | } |
| 2085 | |
| 2086 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2087 | shell_surface_set_title(struct wl_client *client, |
| 2088 | struct wl_resource *resource, const char *title) |
| 2089 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2090 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2091 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2092 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | static void |
| 2096 | shell_surface_set_class(struct wl_client *client, |
| 2097 | struct wl_resource *resource, const char *class) |
| 2098 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2099 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2100 | |
| 2101 | free(shsurf->class); |
| 2102 | shsurf->class = strdup(class); |
| 2103 | } |
| 2104 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2105 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2106 | restore_output_mode(struct weston_output *output) |
| 2107 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2108 | if (output->current_mode != output->original_mode || |
| 2109 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2110 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2111 | output->original_mode, |
| 2112 | output->original_scale, |
| 2113 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | static void |
| 2117 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2118 | { |
| 2119 | struct weston_output *output; |
| 2120 | |
| 2121 | wl_list_for_each(output, &compositor->output_list, link) |
| 2122 | restore_output_mode(output); |
| 2123 | } |
| 2124 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2125 | static int |
| 2126 | get_output_panel_height(struct desktop_shell *shell, |
| 2127 | struct weston_output *output) |
| 2128 | { |
| 2129 | struct weston_view *view; |
| 2130 | int panel_height = 0; |
| 2131 | |
| 2132 | if (!output) |
| 2133 | return 0; |
| 2134 | |
| 2135 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2136 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2137 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2138 | break; |
| 2139 | } |
| 2140 | } |
| 2141 | |
| 2142 | return panel_height; |
| 2143 | } |
| 2144 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2145 | /* The surface will be inserted into the list immediately after the link |
| 2146 | * returned by this function (i.e. will be stacked immediately above the |
| 2147 | * returned link). */ |
| 2148 | static struct wl_list * |
| 2149 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2150 | { |
| 2151 | struct workspace *ws; |
| 2152 | |
| 2153 | switch (shsurf->type) { |
Philip Withnall | da704d9 | 2013-11-25 18:01:46 +0000 | [diff] [blame] | 2154 | case SHELL_SURFACE_POPUP: { |
| 2155 | /* Popups should go at the front of the workspace of their |
| 2156 | * parent surface, rather than just in front of the parent. This |
| 2157 | * fixes the situation where there are two top-level windows: |
| 2158 | * - Above |
| 2159 | * - Below |
| 2160 | * and a pop-up menu is created for 'Below'. We want: |
| 2161 | * - Popup |
| 2162 | * - Above |
| 2163 | * - Below |
| 2164 | * not: |
| 2165 | * - Above |
| 2166 | * - Popup |
| 2167 | * - Below |
| 2168 | */ |
| 2169 | struct shell_surface *parent_shsurf; |
| 2170 | |
| 2171 | parent_shsurf = get_shell_surface(shsurf->parent); |
| 2172 | if (parent_shsurf != NULL) |
| 2173 | return shell_surface_calculate_layer_link(parent_shsurf); |
| 2174 | |
| 2175 | break; |
| 2176 | } |
| 2177 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2178 | case SHELL_SURFACE_TOPLEVEL: { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2179 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2180 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2181 | } else if (shsurf->parent) { |
| 2182 | /* Move the surface to its parent layer so that |
| 2183 | * surfaces which are transient for fullscreen surfaces |
| 2184 | * don't get hidden by the fullscreen surfaces. |
| 2185 | * However, unlike popups, transient surfaces are |
| 2186 | * stacked in front of their parent but not in front of |
| 2187 | * other surfaces of the same type. */ |
| 2188 | struct weston_view *parent; |
| 2189 | |
| 2190 | /* TODO: Handle a parent with multiple views */ |
| 2191 | parent = get_default_view(shsurf->parent); |
| 2192 | if (parent) |
| 2193 | return parent->layer_link.prev; |
| 2194 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2195 | break; |
| 2196 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2197 | |
| 2198 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2199 | case SHELL_SURFACE_NONE: |
| 2200 | default: |
| 2201 | /* Go to the fallback, below. */ |
| 2202 | break; |
| 2203 | } |
| 2204 | |
| 2205 | /* Move the surface to a normal workspace layer so that surfaces |
| 2206 | * which were previously fullscreen or transient are no longer |
| 2207 | * rendered on top. */ |
| 2208 | ws = get_current_workspace(shsurf->shell); |
| 2209 | return &ws->layer.view_list; |
| 2210 | } |
| 2211 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2212 | static void |
| 2213 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2214 | { |
| 2215 | struct shell_surface *child; |
| 2216 | |
| 2217 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2218 | * stacked above shsurf. */ |
| 2219 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2220 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2221 | weston_view_geometry_dirty(child->view); |
| 2222 | wl_list_remove(&child->view->layer_link); |
| 2223 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2224 | &child->view->layer_link); |
| 2225 | weston_view_geometry_dirty(child->view); |
| 2226 | weston_surface_damage(child->surface); |
| 2227 | |
| 2228 | /* Recurse. We don’t expect this to recurse very far (if |
| 2229 | * at all) because that would imply we have transient |
| 2230 | * (or popup) children of transient surfaces, which |
| 2231 | * would be unusual. */ |
| 2232 | shell_surface_update_child_surface_layers(child); |
| 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2237 | /* Update the surface’s layer. Mark both the old and new views as having dirty |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2238 | * geometry to ensure the changes are redrawn. |
| 2239 | * |
| 2240 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2241 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2242 | static void |
| 2243 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2244 | { |
| 2245 | struct wl_list *new_layer_link; |
| 2246 | |
| 2247 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2248 | |
| 2249 | if (new_layer_link == &shsurf->view->layer_link) |
| 2250 | return; |
| 2251 | |
| 2252 | weston_view_geometry_dirty(shsurf->view); |
| 2253 | wl_list_remove(&shsurf->view->layer_link); |
| 2254 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2255 | weston_view_geometry_dirty(shsurf->view); |
| 2256 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2257 | |
| 2258 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2259 | } |
| 2260 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2261 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2262 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2263 | struct weston_surface *parent) |
| 2264 | { |
| 2265 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2266 | |
| 2267 | wl_list_remove(&shsurf->children_link); |
| 2268 | wl_list_init(&shsurf->children_link); |
| 2269 | |
| 2270 | /* Insert into the parent surface’s child list. */ |
| 2271 | if (parent != NULL) { |
| 2272 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2273 | if (parent_shsurf != NULL) |
| 2274 | wl_list_insert(&parent_shsurf->children_list, |
| 2275 | &shsurf->children_link); |
| 2276 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2280 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2281 | struct weston_output *output) |
| 2282 | { |
| 2283 | struct weston_surface *es = shsurf->surface; |
| 2284 | |
| 2285 | /* get the default output, if the client set it as NULL |
| 2286 | check whether the ouput is available */ |
| 2287 | if (output) |
| 2288 | shsurf->output = output; |
| 2289 | else if (es->output) |
| 2290 | shsurf->output = es->output; |
| 2291 | else |
| 2292 | shsurf->output = get_default_output(es->compositor); |
| 2293 | } |
| 2294 | |
| 2295 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2296 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2297 | { |
| 2298 | shsurf->next_state.maximized = false; |
| 2299 | shsurf->next_state.fullscreen = false; |
| 2300 | |
| 2301 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2302 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2303 | shsurf->state_changed = true; |
| 2304 | } |
| 2305 | |
| 2306 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2307 | set_toplevel(struct shell_surface *shsurf) |
| 2308 | { |
| 2309 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2310 | |
| 2311 | /* The layer_link is updated in set_surface_type(), |
| 2312 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | static void |
| 2316 | shell_surface_set_toplevel(struct wl_client *client, |
| 2317 | struct wl_resource *resource) |
| 2318 | { |
| 2319 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2320 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2321 | shell_surface_set_parent(surface, NULL); |
| 2322 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2323 | surface_clear_next_states(surface); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2324 | set_toplevel(surface); |
| 2325 | } |
| 2326 | |
| 2327 | static void |
| 2328 | set_transient(struct shell_surface *shsurf, |
| 2329 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2330 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2331 | assert(parent != NULL); |
| 2332 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2333 | shsurf->transient.x = x; |
| 2334 | shsurf->transient.y = y; |
| 2335 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2336 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2337 | shsurf->next_state.relative = true; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2338 | |
| 2339 | /* The layer_link is updated in set_surface_type(), |
| 2340 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | static void |
| 2344 | shell_surface_set_transient(struct wl_client *client, |
| 2345 | struct wl_resource *resource, |
| 2346 | struct wl_resource *parent_resource, |
| 2347 | int x, int y, uint32_t flags) |
| 2348 | { |
| 2349 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2350 | struct weston_surface *parent = |
| 2351 | wl_resource_get_user_data(parent_resource); |
| 2352 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2353 | shell_surface_set_parent(shsurf, parent); |
| 2354 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2355 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2356 | set_transient(shsurf, parent, x, y, flags); |
| 2357 | } |
| 2358 | |
| 2359 | static void |
| 2360 | set_fullscreen(struct shell_surface *shsurf, |
| 2361 | uint32_t method, |
| 2362 | uint32_t framerate, |
| 2363 | struct weston_output *output) |
| 2364 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2365 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2366 | |
| 2367 | shsurf->fullscreen_output = shsurf->output; |
| 2368 | shsurf->fullscreen.type = method; |
| 2369 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2370 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2371 | shsurf->next_type = shsurf->type; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2372 | |
| 2373 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2374 | shsurf->output->width, |
| 2375 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2376 | |
| 2377 | /* The layer_link is updated in set_surface_type(), |
| 2378 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | static void |
| 2382 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2383 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2384 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2385 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2386 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2387 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2388 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2389 | shsurf->fullscreen_output = NULL; |
| 2390 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2391 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2392 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2393 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2394 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2395 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2396 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2397 | if (shsurf->fullscreen.black_view) |
| 2398 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2399 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2400 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2401 | weston_view_set_position(shsurf->view, |
| 2402 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2403 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2404 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2405 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2406 | shsurf->saved_rotation_valid = false; |
| 2407 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2408 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2409 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2410 | } |
| 2411 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2412 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2413 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2414 | struct wl_resource *resource, |
| 2415 | uint32_t method, |
| 2416 | uint32_t framerate, |
| 2417 | struct wl_resource *output_resource) |
| 2418 | { |
| 2419 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2420 | struct weston_output *output; |
| 2421 | |
| 2422 | if (output_resource) |
| 2423 | output = wl_resource_get_user_data(output_resource); |
| 2424 | else |
| 2425 | output = NULL; |
| 2426 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2427 | shell_surface_set_parent(shsurf, NULL); |
| 2428 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2429 | surface_clear_next_states(shsurf); |
| 2430 | shsurf->next_state.fullscreen = true; |
| 2431 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2432 | set_fullscreen(shsurf, method, framerate, output); |
| 2433 | } |
| 2434 | |
| 2435 | static void |
| 2436 | set_popup(struct shell_surface *shsurf, |
| 2437 | struct weston_surface *parent, |
| 2438 | struct weston_seat *seat, |
| 2439 | uint32_t serial, |
| 2440 | int32_t x, |
| 2441 | int32_t y) |
| 2442 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2443 | assert(parent != NULL); |
| 2444 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2445 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2446 | shsurf->popup.serial = serial; |
| 2447 | shsurf->popup.x = x; |
| 2448 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2449 | |
Philip Withnall | b995e1d | 2013-11-25 18:01:39 +0000 | [diff] [blame] | 2450 | shsurf->next_type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | static void |
| 2454 | shell_surface_set_popup(struct wl_client *client, |
| 2455 | struct wl_resource *resource, |
| 2456 | struct wl_resource *seat_resource, |
| 2457 | uint32_t serial, |
| 2458 | struct wl_resource *parent_resource, |
| 2459 | int32_t x, int32_t y, uint32_t flags) |
| 2460 | { |
| 2461 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2462 | struct weston_surface *parent = |
| 2463 | wl_resource_get_user_data(parent_resource); |
| 2464 | |
| 2465 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2466 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2467 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2468 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2469 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2470 | wl_resource_get_user_data(seat_resource), |
| 2471 | serial, x, y); |
| 2472 | } |
| 2473 | |
| 2474 | static void |
| 2475 | set_maximized(struct shell_surface *shsurf, |
| 2476 | struct weston_output *output) |
| 2477 | { |
| 2478 | struct desktop_shell *shell; |
| 2479 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2480 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2481 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2482 | |
| 2483 | shell = shell_surface_get_shell(shsurf); |
| 2484 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2485 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2486 | |
| 2487 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2488 | shsurf->output->width, |
| 2489 | shsurf->output->height - panel_height); |
| 2490 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2491 | shsurf->next_type = shsurf->type; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | static void |
| 2495 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2496 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2497 | /* undo all maximized things here */ |
| 2498 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2499 | weston_view_set_position(shsurf->view, |
| 2500 | shsurf->saved_x, |
| 2501 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2502 | |
| 2503 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2504 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2505 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2506 | shsurf->saved_rotation_valid = false; |
| 2507 | } |
| 2508 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2509 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2512 | static void |
| 2513 | shell_surface_set_maximized(struct wl_client *client, |
| 2514 | struct wl_resource *resource, |
| 2515 | struct wl_resource *output_resource) |
| 2516 | { |
| 2517 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2518 | struct weston_output *output; |
| 2519 | |
| 2520 | if (output_resource) |
| 2521 | output = wl_resource_get_user_data(output_resource); |
| 2522 | else |
| 2523 | output = NULL; |
| 2524 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2525 | shell_surface_set_parent(shsurf, NULL); |
| 2526 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2527 | surface_clear_next_states(shsurf); |
| 2528 | shsurf->next_state.maximized = true; |
| 2529 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2530 | set_maximized(shsurf, output); |
| 2531 | } |
| 2532 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2533 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2534 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2535 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2536 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2537 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2538 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2539 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2540 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2541 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2542 | |
| 2543 | surface->type = SHELL_SURFACE_NONE; |
| 2544 | return 0; |
| 2545 | } |
| 2546 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2547 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2548 | set_full_output(struct shell_surface *shsurf) |
| 2549 | { |
| 2550 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2551 | shsurf->saved_y = shsurf->view->geometry.y; |
| 2552 | shsurf->saved_position_valid = true; |
| 2553 | |
| 2554 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2555 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2556 | wl_list_init(&shsurf->rotation.transform.link); |
| 2557 | weston_view_geometry_dirty(shsurf->view); |
| 2558 | shsurf->saved_rotation_valid = true; |
| 2559 | } |
| 2560 | } |
| 2561 | |
| 2562 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2563 | set_surface_type(struct shell_surface *shsurf) |
| 2564 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2565 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2566 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2567 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2568 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2569 | |
| 2570 | shsurf->type = shsurf->next_type; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2571 | shsurf->state = shsurf->next_state; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2572 | shsurf->next_type = SHELL_SURFACE_NONE; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2573 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2574 | |
| 2575 | switch (shsurf->type) { |
| 2576 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2577 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2578 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2579 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2580 | weston_view_set_position(shsurf->view, |
| 2581 | pev->geometry.x + shsurf->transient.x, |
| 2582 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2583 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2584 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2585 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2586 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2587 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2588 | break; |
| 2589 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2590 | case SHELL_SURFACE_POPUP: |
| 2591 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2592 | default: |
| 2593 | break; |
| 2594 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2595 | |
| 2596 | /* Update the surface’s layer. */ |
| 2597 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2598 | } |
| 2599 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2600 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2601 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2602 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2603 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2604 | } |
| 2605 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2606 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2607 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy); |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2608 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2609 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2610 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2611 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2612 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2613 | { |
| 2614 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2615 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2616 | |
| 2617 | surface = weston_surface_create(ec); |
| 2618 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2619 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2620 | return NULL; |
| 2621 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2622 | view = weston_view_create(surface); |
| 2623 | if (surface == NULL) { |
| 2624 | weston_log("no memory\n"); |
| 2625 | weston_surface_destroy(surface); |
| 2626 | return NULL; |
| 2627 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2628 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2629 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2630 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2631 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2632 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2633 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2634 | pixman_region32_fini(&surface->input); |
| 2635 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2636 | |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2637 | surface->width = w; |
| 2638 | surface->height = h; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2639 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2640 | |
| 2641 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2642 | } |
| 2643 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2644 | static void |
| 2645 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2646 | { |
| 2647 | struct weston_output *output = shsurf->fullscreen_output; |
| 2648 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2649 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2650 | |
| 2651 | if (!shsurf->fullscreen.black_view) |
| 2652 | shsurf->fullscreen.black_view = |
| 2653 | create_black_surface(shsurf->surface->compositor, |
| 2654 | shsurf->surface, |
| 2655 | output->x, output->y, |
| 2656 | output->width, |
| 2657 | output->height); |
| 2658 | |
| 2659 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2660 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2661 | wl_list_insert(&shsurf->view->layer_link, |
| 2662 | &shsurf->fullscreen.black_view->layer_link); |
| 2663 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2664 | weston_surface_damage(shsurf->surface); |
| 2665 | } |
| 2666 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2667 | /* Create black surface and append it to the associated fullscreen surface. |
| 2668 | * Handle size dismatch and positioning according to the method. */ |
| 2669 | static void |
| 2670 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2671 | { |
| 2672 | struct weston_output *output = shsurf->fullscreen_output; |
| 2673 | struct weston_surface *surface = shsurf->surface; |
| 2674 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2675 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2676 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2677 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2678 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2679 | restore_output_mode(output); |
| 2680 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2681 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2682 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2683 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2684 | &surf_width, &surf_height); |
| 2685 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2686 | switch (shsurf->fullscreen.type) { |
| 2687 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2688 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2689 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2690 | break; |
| 2691 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2692 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2693 | if (output->width == surf_width && |
| 2694 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2695 | weston_view_set_position(shsurf->view, |
| 2696 | output->x - surf_x, |
| 2697 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2698 | break; |
| 2699 | } |
| 2700 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2701 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2702 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2703 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2704 | output_aspect = (float) output->width / |
| 2705 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2706 | /* XXX: Use surf_width and surf_height here? */ |
| 2707 | surface_aspect = (float) surface->width / |
| 2708 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2709 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2710 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2711 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2712 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2713 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2714 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2715 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2716 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2717 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2718 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2719 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2720 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2721 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2722 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2723 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2724 | break; |
| 2725 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2726 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2727 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2728 | surf_width * surface->buffer_viewport.scale, |
| 2729 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2730 | shsurf->fullscreen.framerate}; |
| 2731 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2732 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2733 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2734 | weston_view_set_position(shsurf->view, |
| 2735 | output->x - surf_x, |
| 2736 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2737 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2738 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2739 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2740 | output->x - surf_x, |
| 2741 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2742 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2743 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2744 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2745 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2746 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2747 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2748 | break; |
| 2749 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2750 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2751 | break; |
| 2752 | default: |
| 2753 | break; |
| 2754 | } |
| 2755 | } |
| 2756 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2757 | static void |
| 2758 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2759 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2760 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2761 | } |
| 2762 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2763 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2764 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2765 | { |
| 2766 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2767 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2768 | shsurf->transient.x = x; |
| 2769 | shsurf->transient.y = y; |
| 2770 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2771 | |
| 2772 | shell_surface_set_parent(shsurf, NULL); |
| 2773 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2774 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2775 | } |
| 2776 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2777 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2778 | |
| 2779 | static void |
| 2780 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2781 | { |
| 2782 | struct shell_seat *shseat = |
| 2783 | container_of(listener, |
| 2784 | struct shell_seat, seat_destroy_listener); |
| 2785 | struct shell_surface *shsurf, *prev = NULL; |
| 2786 | |
| 2787 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2788 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2789 | shseat->popup_grab.client = NULL; |
| 2790 | |
| 2791 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2792 | shsurf->popup.shseat = NULL; |
| 2793 | if (prev) { |
| 2794 | wl_list_init(&prev->popup.grab_link); |
| 2795 | } |
| 2796 | prev = shsurf; |
| 2797 | } |
| 2798 | wl_list_init(&prev->popup.grab_link); |
| 2799 | } |
| 2800 | |
| 2801 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2802 | free(shseat); |
| 2803 | } |
| 2804 | |
| 2805 | static struct shell_seat * |
| 2806 | create_shell_seat(struct weston_seat *seat) |
| 2807 | { |
| 2808 | struct shell_seat *shseat; |
| 2809 | |
| 2810 | shseat = calloc(1, sizeof *shseat); |
| 2811 | if (!shseat) { |
| 2812 | weston_log("no memory to allocate shell seat\n"); |
| 2813 | return NULL; |
| 2814 | } |
| 2815 | |
| 2816 | shseat->seat = seat; |
| 2817 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2818 | |
| 2819 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2820 | wl_signal_add(&seat->destroy_signal, |
| 2821 | &shseat->seat_destroy_listener); |
| 2822 | |
| 2823 | return shseat; |
| 2824 | } |
| 2825 | |
| 2826 | static struct shell_seat * |
| 2827 | get_shell_seat(struct weston_seat *seat) |
| 2828 | { |
| 2829 | struct wl_listener *listener; |
| 2830 | |
| 2831 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2832 | if (listener == NULL) |
| 2833 | return create_shell_seat(seat); |
| 2834 | |
| 2835 | return container_of(listener, |
| 2836 | struct shell_seat, seat_destroy_listener); |
| 2837 | } |
| 2838 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2839 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2840 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2841 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2842 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2843 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2844 | struct shell_seat *shseat = |
| 2845 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2846 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2847 | wl_fixed_t sx, sy; |
| 2848 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2849 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2850 | pointer->x, pointer->y, |
| 2851 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2852 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2853 | if (view && view->surface->resource && |
| 2854 | wl_resource_get_client(view->surface->resource) == client) { |
| 2855 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2856 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2857 | weston_pointer_set_focus(pointer, NULL, |
| 2858 | wl_fixed_from_int(0), |
| 2859 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2864 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2865 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2866 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2867 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2868 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2869 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2870 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2871 | weston_pointer_move(pointer, x, y); |
| 2872 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2873 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2874 | weston_view_from_global_fixed(pointer->focus, |
| 2875 | pointer->x, pointer->y, |
| 2876 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2877 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2878 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2882 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2883 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2884 | { |
| 2885 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2886 | struct shell_seat *shseat = |
| 2887 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2888 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2889 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2890 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2891 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2892 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2893 | resource_list = &grab->pointer->focus_resource_list; |
| 2894 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2895 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2896 | wl_resource_for_each(resource, resource_list) { |
| 2897 | wl_pointer_send_button(resource, serial, |
| 2898 | time, button, state); |
| 2899 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2900 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2901 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2902 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2903 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2904 | } |
| 2905 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2906 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2907 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2908 | } |
| 2909 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2910 | static void |
| 2911 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2912 | { |
| 2913 | popup_grab_end(grab->pointer); |
| 2914 | } |
| 2915 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2916 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2917 | popup_grab_focus, |
| 2918 | popup_grab_motion, |
| 2919 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2920 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2921 | }; |
| 2922 | |
| 2923 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 2924 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2925 | { |
| 2926 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2927 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2928 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2929 | xdg_popup_send_popup_done(shsurf->resource, |
| 2930 | shsurf->popup.serial); |
| 2931 | } |
| 2932 | |
| 2933 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2934 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2935 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2936 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2937 | struct shell_seat *shseat = |
| 2938 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2939 | struct shell_surface *shsurf; |
| 2940 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2941 | |
| 2942 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2943 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2944 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2945 | shseat->popup_grab.grab.interface = NULL; |
| 2946 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2947 | /* Send the popup_done event to all the popups open */ |
| 2948 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 2949 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2950 | shsurf->popup.shseat = NULL; |
| 2951 | if (prev) { |
| 2952 | wl_list_init(&prev->popup.grab_link); |
| 2953 | } |
| 2954 | prev = shsurf; |
| 2955 | } |
| 2956 | wl_list_init(&prev->popup.grab_link); |
| 2957 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | static void |
| 2962 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2963 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2964 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2965 | |
| 2966 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2967 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2968 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2969 | /* We must make sure here that this popup was opened after |
| 2970 | * a mouse press, and not just by moving around with other |
| 2971 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2972 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2973 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2974 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2975 | 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] | 2976 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2977 | } else { |
| 2978 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2979 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | static void |
| 2983 | remove_popup_grab(struct shell_surface *shsurf) |
| 2984 | { |
| 2985 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2986 | |
| 2987 | wl_list_remove(&shsurf->popup.grab_link); |
| 2988 | wl_list_init(&shsurf->popup.grab_link); |
| 2989 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2990 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2991 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2996 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2997 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2998 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2999 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3000 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3001 | shsurf->surface->output = parent_view->output; |
| 3002 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3003 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3004 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3005 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3006 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3007 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3008 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3009 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3010 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 3011 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3012 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3013 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3014 | } |
| 3015 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3016 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3017 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3018 | shell_surface_move, |
| 3019 | shell_surface_resize, |
| 3020 | shell_surface_set_toplevel, |
| 3021 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3022 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3023 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3024 | shell_surface_set_maximized, |
| 3025 | shell_surface_set_title, |
| 3026 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3027 | }; |
| 3028 | |
| 3029 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3030 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3031 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3032 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3033 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3034 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3035 | remove_popup_grab(shsurf); |
| 3036 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3037 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3038 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3039 | shell_surface_is_top_fullscreen(shsurf)) |
| 3040 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3041 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3042 | if (shsurf->fullscreen.black_view) |
| 3043 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3044 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3045 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3046 | * we can always remove the listener. |
| 3047 | */ |
| 3048 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3049 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 3050 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3051 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3052 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3053 | weston_view_destroy(shsurf->view); |
| 3054 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3055 | wl_list_remove(&shsurf->children_link); |
| 3056 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3057 | wl_list_remove(&shsurf->link); |
| 3058 | free(shsurf); |
| 3059 | } |
| 3060 | |
| 3061 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3062 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3063 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3064 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3065 | |
| 3066 | destroy_shell_surface(shsurf); |
| 3067 | } |
| 3068 | |
| 3069 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3070 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3071 | { |
| 3072 | struct shell_surface *shsurf = container_of(listener, |
| 3073 | struct shell_surface, |
| 3074 | surface_destroy_listener); |
| 3075 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3076 | if (shsurf->resource) |
| 3077 | wl_resource_destroy(shsurf->resource); |
| 3078 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3079 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3080 | } |
| 3081 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3082 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3083 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3084 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3085 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3086 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3087 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3088 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3089 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3090 | else |
| 3091 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3092 | } |
| 3093 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 3094 | static struct shell_surface * |
| 3095 | create_common_surface(void *shell, struct weston_surface *surface, |
| 3096 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3097 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3098 | struct shell_surface *shsurf; |
| 3099 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3100 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3101 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3102 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3103 | } |
| 3104 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3105 | shsurf = calloc(1, sizeof *shsurf); |
| 3106 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3107 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3108 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3109 | } |
| 3110 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3111 | shsurf->view = weston_view_create(surface); |
| 3112 | if (!shsurf->view) { |
| 3113 | weston_log("no memory to allocate shell surface\n"); |
| 3114 | free(shsurf); |
| 3115 | return NULL; |
| 3116 | } |
| 3117 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3118 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3119 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3120 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3121 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3122 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3123 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3124 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3125 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3126 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3127 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3128 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3129 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3130 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3131 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3132 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3133 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3134 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3135 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3136 | |
| 3137 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3138 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3139 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3140 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3141 | /* empty when not in use */ |
| 3142 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3143 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3144 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3145 | wl_list_init(&shsurf->workspace_transform.link); |
| 3146 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3147 | wl_list_init(&shsurf->children_link); |
| 3148 | wl_list_init(&shsurf->children_list); |
| 3149 | shsurf->parent = NULL; |
| 3150 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3151 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3152 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3153 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3154 | shsurf->client = client; |
| 3155 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3156 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3157 | } |
| 3158 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 3159 | static struct shell_surface * |
| 3160 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3161 | const struct weston_shell_client *client) |
| 3162 | { |
| 3163 | struct shell_surface *shsurf; |
| 3164 | shsurf = create_common_surface(shell, surface, client); |
| 3165 | |
| 3166 | shsurf->type = SHELL_SURFACE_NONE; |
| 3167 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 3168 | |
| 3169 | return shsurf; |
| 3170 | } |
| 3171 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3172 | static struct weston_view * |
| 3173 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3174 | { |
| 3175 | return shsurf->view; |
| 3176 | } |
| 3177 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3178 | static void |
| 3179 | shell_get_shell_surface(struct wl_client *client, |
| 3180 | struct wl_resource *resource, |
| 3181 | uint32_t id, |
| 3182 | struct wl_resource *surface_resource) |
| 3183 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3184 | struct weston_surface *surface = |
| 3185 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3186 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3187 | struct shell_surface *shsurf; |
| 3188 | |
| 3189 | if (get_shell_surface(surface)) { |
| 3190 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3191 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3192 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3193 | return; |
| 3194 | } |
| 3195 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3196 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3197 | if (!shsurf) { |
| 3198 | wl_resource_post_error(surface_resource, |
| 3199 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3200 | "surface->configure already set"); |
| 3201 | return; |
| 3202 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3203 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3204 | shsurf->resource = |
| 3205 | wl_resource_create(client, |
| 3206 | &wl_shell_surface_interface, 1, id); |
| 3207 | wl_resource_set_implementation(shsurf->resource, |
| 3208 | &shell_surface_implementation, |
| 3209 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3210 | } |
| 3211 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 3212 | static bool |
| 3213 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3214 | { |
| 3215 | return wl_resource_instance_of(shsurf->resource, |
| 3216 | &wl_shell_surface_interface, |
| 3217 | &shell_surface_implementation); |
| 3218 | } |
| 3219 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3220 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3221 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3222 | }; |
| 3223 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 3224 | /**************************** |
| 3225 | * xdg-shell implementation */ |
| 3226 | |
| 3227 | static void |
| 3228 | xdg_surface_destroy(struct wl_client *client, |
| 3229 | struct wl_resource *resource) |
| 3230 | { |
| 3231 | wl_resource_destroy(resource); |
| 3232 | } |
| 3233 | |
| 3234 | static void |
| 3235 | xdg_surface_pong(struct wl_client *client, |
| 3236 | struct wl_resource *resource, |
| 3237 | uint32_t serial) |
| 3238 | { |
| 3239 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3240 | |
| 3241 | surface_pong(shsurf, serial); |
| 3242 | } |
| 3243 | |
| 3244 | static void |
| 3245 | xdg_surface_set_app_id(struct wl_client *client, |
| 3246 | struct wl_resource *resource, |
| 3247 | const char *app_id) |
| 3248 | { |
| 3249 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3250 | |
| 3251 | free(shsurf->class); |
| 3252 | shsurf->class = strdup(app_id); |
| 3253 | } |
| 3254 | |
| 3255 | static void |
| 3256 | xdg_surface_set_title(struct wl_client *client, |
| 3257 | struct wl_resource *resource, const char *title) |
| 3258 | { |
| 3259 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3260 | |
| 3261 | set_title(shsurf, title); |
| 3262 | } |
| 3263 | |
| 3264 | static void |
| 3265 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3266 | struct wl_resource *seat_resource, uint32_t serial) |
| 3267 | { |
| 3268 | common_surface_move(resource, seat_resource, serial); |
| 3269 | } |
| 3270 | |
| 3271 | static void |
| 3272 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3273 | struct wl_resource *seat_resource, uint32_t serial, |
| 3274 | uint32_t edges) |
| 3275 | { |
| 3276 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3277 | } |
| 3278 | |
| 3279 | static void |
| 3280 | xdg_surface_set_output(struct wl_client *client, |
| 3281 | struct wl_resource *resource, |
| 3282 | struct wl_resource *output_resource) |
| 3283 | { |
| 3284 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3285 | struct weston_output *output; |
| 3286 | |
| 3287 | if (output_resource) |
| 3288 | output = wl_resource_get_user_data(output_resource); |
| 3289 | else |
| 3290 | output = NULL; |
| 3291 | |
| 3292 | if (!weston_surface_is_mapped(shsurf->surface)) |
| 3293 | shsurf->output = output; |
| 3294 | } |
| 3295 | |
| 3296 | static void |
| 3297 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3298 | struct wl_resource *resource) |
| 3299 | { |
| 3300 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3301 | |
| 3302 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3303 | return; |
| 3304 | |
| 3305 | if (!shsurf->next_state.fullscreen) { |
| 3306 | shsurf->next_state.fullscreen = true; |
| 3307 | shsurf->state_changed = true; |
| 3308 | set_fullscreen(shsurf, |
| 3309 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
| 3310 | 0, shsurf->output); |
| 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | static void |
| 3315 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3316 | struct wl_resource *resource) |
| 3317 | { |
| 3318 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3319 | |
| 3320 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3321 | return; |
| 3322 | |
| 3323 | shsurf->next_state.fullscreen = false; |
| 3324 | shsurf->state_changed = true; |
| 3325 | } |
| 3326 | |
| 3327 | static void |
| 3328 | xdg_surface_set_maximized(struct wl_client *client, |
| 3329 | struct wl_resource *resource) |
| 3330 | { |
| 3331 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3332 | |
| 3333 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3334 | return; |
| 3335 | |
| 3336 | if (!shsurf->next_state.maximized) { |
| 3337 | shsurf->next_state.maximized = true; |
| 3338 | shsurf->state_changed = true; |
| 3339 | set_maximized(shsurf, shsurf->output); |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | static void |
| 3344 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3345 | struct wl_resource *resource) |
| 3346 | { |
| 3347 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3348 | |
| 3349 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3350 | return; |
| 3351 | |
| 3352 | shsurf->next_state.maximized = false; |
| 3353 | shsurf->state_changed = true; |
| 3354 | } |
| 3355 | |
| 3356 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3357 | xdg_surface_destroy, |
| 3358 | xdg_surface_set_transient_for, |
| 3359 | xdg_surface_set_title, |
| 3360 | xdg_surface_set_app_id, |
| 3361 | xdg_surface_pong, |
| 3362 | xdg_surface_move, |
| 3363 | xdg_surface_resize, |
| 3364 | xdg_surface_set_output, |
| 3365 | xdg_surface_set_fullscreen, |
| 3366 | xdg_surface_unset_fullscreen, |
| 3367 | xdg_surface_set_maximized, |
| 3368 | xdg_surface_unset_maximized, |
| 3369 | NULL /* set_minimized */ |
| 3370 | }; |
| 3371 | |
| 3372 | static void |
| 3373 | xdg_send_configure(struct weston_surface *surface, |
| 3374 | uint32_t edges, int32_t width, int32_t height) |
| 3375 | { |
| 3376 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3377 | |
| 3378 | xdg_surface_send_configure(shsurf->resource, edges, width, height); |
| 3379 | } |
| 3380 | |
| 3381 | static const struct weston_shell_client xdg_client = { |
| 3382 | xdg_send_configure |
| 3383 | }; |
| 3384 | |
| 3385 | static void |
| 3386 | xdg_use_unstable_version(struct wl_client *client, |
| 3387 | struct wl_resource *resource, |
| 3388 | int32_t version) |
| 3389 | { |
| 3390 | if (version > 1) { |
| 3391 | wl_resource_post_error(resource, |
| 3392 | 1, |
| 3393 | "xdg-shell:: version not implemented yet."); |
| 3394 | return; |
| 3395 | } |
| 3396 | } |
| 3397 | |
| 3398 | static struct shell_surface * |
| 3399 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3400 | const struct weston_shell_client *client) |
| 3401 | { |
| 3402 | struct shell_surface *shsurf; |
| 3403 | shsurf = create_common_surface(shell, surface, client); |
| 3404 | |
| 3405 | shsurf->type = SHELL_SURFACE_NONE; |
| 3406 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
| 3407 | |
| 3408 | return shsurf; |
| 3409 | } |
| 3410 | |
| 3411 | static void |
| 3412 | xdg_get_xdg_surface(struct wl_client *client, |
| 3413 | struct wl_resource *resource, |
| 3414 | uint32_t id, |
| 3415 | struct wl_resource *surface_resource) |
| 3416 | { |
| 3417 | struct weston_surface *surface = |
| 3418 | wl_resource_get_user_data(surface_resource); |
| 3419 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3420 | struct shell_surface *shsurf; |
| 3421 | |
| 3422 | if (get_shell_surface(surface)) { |
| 3423 | wl_resource_post_error(surface_resource, |
| 3424 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3425 | "desktop_shell::get_shell_surface already requested"); |
| 3426 | return; |
| 3427 | } |
| 3428 | |
| 3429 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3430 | if (!shsurf) { |
| 3431 | wl_resource_post_error(surface_resource, |
| 3432 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3433 | "surface->configure already set"); |
| 3434 | return; |
| 3435 | } |
| 3436 | |
| 3437 | shsurf->resource = |
| 3438 | wl_resource_create(client, |
| 3439 | &xdg_surface_interface, 1, id); |
| 3440 | wl_resource_set_implementation(shsurf->resource, |
| 3441 | &xdg_surface_implementation, |
| 3442 | shsurf, shell_destroy_shell_surface); |
| 3443 | } |
| 3444 | |
| 3445 | static bool |
| 3446 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3447 | { |
| 3448 | return wl_resource_instance_of(shsurf->resource, |
| 3449 | &xdg_surface_interface, |
| 3450 | &xdg_surface_implementation); |
| 3451 | } |
| 3452 | |
| 3453 | /* xdg-popup implementation */ |
| 3454 | |
| 3455 | static void |
| 3456 | xdg_popup_destroy(struct wl_client *client, |
| 3457 | struct wl_resource *resource) |
| 3458 | { |
| 3459 | wl_resource_destroy(resource); |
| 3460 | } |
| 3461 | |
| 3462 | static void |
| 3463 | xdg_popup_pong(struct wl_client *client, |
| 3464 | struct wl_resource *resource, |
| 3465 | uint32_t serial) |
| 3466 | { |
| 3467 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3468 | |
| 3469 | surface_pong(shsurf, serial); |
| 3470 | } |
| 3471 | |
| 3472 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3473 | xdg_popup_destroy, |
| 3474 | xdg_popup_pong |
| 3475 | }; |
| 3476 | |
| 3477 | static void |
| 3478 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3479 | uint32_t edges, int32_t width, int32_t height) |
| 3480 | { |
| 3481 | } |
| 3482 | |
| 3483 | static const struct weston_shell_client xdg_popup_client = { |
| 3484 | xdg_popup_send_configure |
| 3485 | }; |
| 3486 | |
| 3487 | static struct shell_surface * |
| 3488 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3489 | const struct weston_shell_client *client, |
| 3490 | struct weston_surface *parent, |
| 3491 | struct shell_seat *seat, |
| 3492 | uint32_t serial, |
| 3493 | int32_t x, int32_t y) |
| 3494 | { |
| 3495 | struct shell_surface *shsurf; |
| 3496 | shsurf = create_common_surface(shell, surface, client); |
| 3497 | |
| 3498 | shsurf->type = SHELL_SURFACE_NONE; |
| 3499 | shsurf->next_type = SHELL_SURFACE_POPUP; |
| 3500 | shsurf->popup.shseat = seat; |
| 3501 | shsurf->popup.serial = serial; |
| 3502 | shsurf->popup.x = x; |
| 3503 | shsurf->popup.y = y; |
| 3504 | shell_surface_set_parent(shsurf, parent); |
| 3505 | |
| 3506 | return shsurf; |
| 3507 | } |
| 3508 | |
| 3509 | static void |
| 3510 | xdg_get_xdg_popup(struct wl_client *client, |
| 3511 | struct wl_resource *resource, |
| 3512 | uint32_t id, |
| 3513 | struct wl_resource *surface_resource, |
| 3514 | struct wl_resource *parent_resource, |
| 3515 | struct wl_resource *seat_resource, |
| 3516 | uint32_t serial, |
| 3517 | int32_t x, int32_t y, uint32_t flags) |
| 3518 | { |
| 3519 | struct weston_surface *surface = |
| 3520 | wl_resource_get_user_data(surface_resource); |
| 3521 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3522 | struct shell_surface *shsurf; |
| 3523 | struct weston_surface *parent; |
| 3524 | struct shell_seat *seat; |
| 3525 | |
| 3526 | if (get_shell_surface(surface)) { |
| 3527 | wl_resource_post_error(surface_resource, |
| 3528 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3529 | "desktop_shell::get_shell_surface already requested"); |
| 3530 | return; |
| 3531 | } |
| 3532 | |
| 3533 | if (!parent_resource) { |
| 3534 | wl_resource_post_error(surface_resource, |
| 3535 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3536 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3537 | } |
| 3538 | |
| 3539 | parent = wl_resource_get_user_data(parent_resource); |
| 3540 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3541 | |
| 3542 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3543 | parent, seat, serial, x, y); |
| 3544 | if (!shsurf) { |
| 3545 | wl_resource_post_error(surface_resource, |
| 3546 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3547 | "surface->configure already set"); |
| 3548 | return; |
| 3549 | } |
| 3550 | |
| 3551 | shsurf->resource = |
| 3552 | wl_resource_create(client, |
| 3553 | &xdg_popup_interface, 1, id); |
| 3554 | wl_resource_set_implementation(shsurf->resource, |
| 3555 | &xdg_popup_implementation, |
| 3556 | shsurf, shell_destroy_shell_surface); |
| 3557 | } |
| 3558 | |
| 3559 | static bool |
| 3560 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3561 | { |
| 3562 | return wl_resource_instance_of(shsurf->resource, |
| 3563 | &xdg_popup_interface, |
| 3564 | &xdg_popup_implementation); |
| 3565 | } |
| 3566 | |
| 3567 | static const struct xdg_shell_interface xdg_implementation = { |
| 3568 | xdg_use_unstable_version, |
| 3569 | xdg_get_xdg_surface, |
| 3570 | xdg_get_xdg_popup |
| 3571 | }; |
| 3572 | |
| 3573 | static int |
| 3574 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3575 | void *_target, uint32_t opcode, |
| 3576 | const struct wl_message *message, |
| 3577 | union wl_argument *args) |
| 3578 | { |
| 3579 | struct wl_resource *resource = _target; |
| 3580 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3581 | |
| 3582 | if (opcode != 0) { |
| 3583 | wl_resource_post_error(resource, |
| 3584 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3585 | "must call use_unstable_version first"); |
| 3586 | return 0; |
| 3587 | } |
| 3588 | |
| 3589 | #define XDG_SERVER_VERSION 1 |
| 3590 | |
| 3591 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3592 | wl_resource_post_error(resource, |
| 3593 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3594 | "incompatible version, server is %d " |
| 3595 | "client wants %d", |
| 3596 | XDG_SERVER_VERSION, args[0].i); |
| 3597 | return 0; |
| 3598 | } |
| 3599 | |
| 3600 | wl_resource_set_implementation(resource, &xdg_implementation, |
| 3601 | shell, NULL); |
| 3602 | |
| 3603 | return 1; |
| 3604 | } |
| 3605 | |
| 3606 | /* end of xdg-shell implementation */ |
| 3607 | /***********************************/ |
| 3608 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3609 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3610 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3611 | |
| 3612 | static int |
| 3613 | screensaver_timeout(void *data) |
| 3614 | { |
| 3615 | struct desktop_shell *shell = data; |
| 3616 | |
| 3617 | shell_fade(shell, FADE_OUT); |
| 3618 | |
| 3619 | return 1; |
| 3620 | } |
| 3621 | |
| 3622 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3623 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3624 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3625 | struct desktop_shell *shell = |
| 3626 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3627 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3628 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3629 | |
| 3630 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3631 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3635 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3636 | { |
| 3637 | if (shell->screensaver.binding) |
| 3638 | return; |
| 3639 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3640 | if (!shell->screensaver.path) { |
| 3641 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3642 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3643 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3644 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3645 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3646 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3647 | return; |
| 3648 | } |
| 3649 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3650 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3651 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3652 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3653 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3654 | } |
| 3655 | |
| 3656 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3657 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3658 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3659 | if (shell->screensaver.process.pid == 0) |
| 3660 | return; |
| 3661 | |
| 3662 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3666 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3667 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3668 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3669 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3670 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3671 | if (v->output == ev->output && v != ev) { |
| 3672 | weston_view_unmap(v); |
| 3673 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3677 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3678 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3679 | if (wl_list_empty(&ev->layer_link)) { |
| 3680 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3681 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3686 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3687 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3688 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3689 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3690 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3691 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3692 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3693 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3697 | desktop_shell_set_background(struct wl_client *client, |
| 3698 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3699 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3700 | struct wl_resource *surface_resource) |
| 3701 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3702 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3703 | struct weston_surface *surface = |
| 3704 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3705 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3706 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3707 | if (surface->configure) { |
| 3708 | wl_resource_post_error(surface_resource, |
| 3709 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3710 | "surface role already assigned"); |
| 3711 | return; |
| 3712 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3713 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3714 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3715 | weston_view_destroy(view); |
| 3716 | view = weston_view_create(surface); |
| 3717 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3718 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3719 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3720 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3721 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3722 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3723 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3724 | surface->output->width, |
| 3725 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3729 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3730 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3731 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3732 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3733 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3734 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3735 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3736 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3740 | desktop_shell_set_panel(struct wl_client *client, |
| 3741 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3742 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3743 | struct wl_resource *surface_resource) |
| 3744 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3745 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3746 | struct weston_surface *surface = |
| 3747 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3748 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3749 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3750 | if (surface->configure) { |
| 3751 | wl_resource_post_error(surface_resource, |
| 3752 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3753 | "surface role already assigned"); |
| 3754 | return; |
| 3755 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3756 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3757 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3758 | weston_view_destroy(view); |
| 3759 | view = weston_view_create(surface); |
| 3760 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3761 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3762 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3763 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3764 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3765 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3766 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3767 | surface->output->width, |
| 3768 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3769 | } |
| 3770 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3771 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3772 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3773 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3774 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3775 | struct weston_view *view; |
| 3776 | |
| 3777 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3778 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3779 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3780 | return; |
| 3781 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3782 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3783 | |
| 3784 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3785 | wl_list_insert(&shell->lock_layer.view_list, |
| 3786 | &view->layer_link); |
| 3787 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3788 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3789 | } |
| 3790 | } |
| 3791 | |
| 3792 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3793 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3794 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3795 | struct desktop_shell *shell = |
| 3796 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3797 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3798 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3799 | shell->lock_surface = NULL; |
| 3800 | } |
| 3801 | |
| 3802 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3803 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3804 | struct wl_resource *resource, |
| 3805 | struct wl_resource *surface_resource) |
| 3806 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3807 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3808 | struct weston_surface *surface = |
| 3809 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3810 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3811 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3812 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3813 | if (!shell->locked) |
| 3814 | return; |
| 3815 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3816 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3817 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3818 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3819 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3820 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3821 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3822 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3823 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3824 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3828 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3829 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3830 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3831 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3832 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3833 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3834 | wl_list_remove(&shell->lock_layer.link); |
| 3835 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3836 | &shell->fullscreen_layer.link); |
| 3837 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3838 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3839 | if (shell->showing_input_panels) { |
| 3840 | wl_list_insert(&shell->panel_layer.link, |
| 3841 | &shell->input_panel_layer.link); |
| 3842 | wl_list_insert(&shell->input_panel_layer.link, |
| 3843 | &ws->layer.link); |
| 3844 | } else { |
| 3845 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3846 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3847 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3848 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3849 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3850 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3851 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3852 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | static void |
| 3856 | desktop_shell_unlock(struct wl_client *client, |
| 3857 | struct wl_resource *resource) |
| 3858 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3859 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3860 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3861 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3862 | |
| 3863 | if (shell->locked) |
| 3864 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3865 | } |
| 3866 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3867 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3868 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3869 | struct wl_resource *resource, |
| 3870 | struct wl_resource *surface_resource) |
| 3871 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3872 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3873 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3874 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3875 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3876 | } |
| 3877 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3878 | static void |
| 3879 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3880 | struct wl_resource *resource) |
| 3881 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3882 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3883 | |
| 3884 | shell_fade_startup(shell); |
| 3885 | } |
| 3886 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3887 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3888 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3889 | desktop_shell_set_panel, |
| 3890 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3891 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3892 | desktop_shell_set_grab_surface, |
| 3893 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3894 | }; |
| 3895 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3896 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3897 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3898 | { |
| 3899 | struct shell_surface *shsurf; |
| 3900 | |
| 3901 | shsurf = get_shell_surface(surface); |
| 3902 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3903 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3904 | return shsurf->type; |
| 3905 | } |
| 3906 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3907 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3908 | 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] | 3909 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3910 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3911 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3912 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3913 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3914 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3915 | if (surface == NULL) |
| 3916 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3917 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3918 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3919 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3920 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3921 | return; |
| 3922 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3923 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3927 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 3928 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3929 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3930 | struct weston_surface *surface; |
| 3931 | struct shell_surface *shsurf; |
| 3932 | |
| 3933 | surface = weston_surface_get_main_surface(focus); |
| 3934 | if (surface == NULL) |
| 3935 | return; |
| 3936 | |
| 3937 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3938 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3939 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 3940 | return; |
| 3941 | |
| 3942 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 3943 | } |
| 3944 | |
| 3945 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3946 | 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] | 3947 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3948 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3949 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3950 | uint32_t edges = 0; |
| 3951 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3952 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3953 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3954 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3955 | if (surface == NULL) |
| 3956 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3957 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3958 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3959 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3960 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3961 | return; |
| 3962 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3963 | weston_view_from_global(shsurf->view, |
| 3964 | wl_fixed_to_int(seat->pointer->grab_x), |
| 3965 | wl_fixed_to_int(seat->pointer->grab_y), |
| 3966 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3967 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3968 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3969 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3970 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3971 | edges |= 0; |
| 3972 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3973 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3974 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3975 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3976 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3977 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3978 | edges |= 0; |
| 3979 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3980 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3981 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3982 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3986 | 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] | 3987 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3988 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 3989 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3990 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 3991 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3992 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3993 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3994 | /* XXX: broken for windows containing sub-surfaces */ |
| 3995 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 3996 | if (surface == NULL) |
| 3997 | return; |
| 3998 | |
| 3999 | shsurf = get_shell_surface(surface); |
| 4000 | if (!shsurf) |
| 4001 | return; |
| 4002 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4003 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4004 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4005 | if (shsurf->view->alpha > 1.0) |
| 4006 | shsurf->view->alpha = 1.0; |
| 4007 | if (shsurf->view->alpha < step) |
| 4008 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4009 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4010 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4011 | weston_surface_damage(surface); |
| 4012 | } |
| 4013 | |
| 4014 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4015 | 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] | 4016 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4017 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4018 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4019 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4020 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4021 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4022 | |
| 4023 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4024 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4025 | wl_fixed_to_double(seat->pointer->x), |
| 4026 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4027 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4028 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4029 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4030 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4031 | increment = -output->zoom.increment; |
| 4032 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4033 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4034 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4035 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4036 | else |
| 4037 | increment = 0; |
| 4038 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4039 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4040 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4041 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4042 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4043 | else if (output->zoom.level > output->zoom.max_level) |
| 4044 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4045 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4046 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4047 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4048 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4049 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4050 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4051 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4052 | } |
| 4053 | } |
| 4054 | } |
| 4055 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4056 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4057 | 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] | 4058 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4059 | { |
| 4060 | do_zoom(seat, time, 0, axis, value); |
| 4061 | } |
| 4062 | |
| 4063 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4064 | 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] | 4065 | void *data) |
| 4066 | { |
| 4067 | do_zoom(seat, time, key, 0, 0); |
| 4068 | } |
| 4069 | |
| 4070 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4071 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4072 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4073 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4074 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4075 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4076 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4080 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 4081 | |
| 4082 | struct alt_tab { |
| 4083 | struct desktop_shell *shell; |
| 4084 | struct weston_keyboard_grab grab; |
| 4085 | |
| 4086 | struct wl_list *current; |
| 4087 | |
| 4088 | struct wl_list preview_list; |
| 4089 | }; |
| 4090 | |
| 4091 | struct alt_tab_preview { |
| 4092 | struct alt_tab *alt_tab; |
| 4093 | |
| 4094 | struct weston_view *view; |
| 4095 | struct weston_transform transform; |
| 4096 | |
| 4097 | struct wl_listener listener; |
| 4098 | |
| 4099 | struct wl_list link; |
| 4100 | }; |
| 4101 | |
| 4102 | static void |
| 4103 | alt_tab_next(struct alt_tab *alt_tab) |
| 4104 | { |
| 4105 | alt_tab->current = alt_tab->current->next; |
| 4106 | |
| 4107 | /* Make sure we're not pointing to the list header e.g. after |
| 4108 | * cycling through the whole list. */ |
| 4109 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 4110 | alt_tab->current = alt_tab->current->next; |
| 4111 | } |
| 4112 | |
| 4113 | static void |
| 4114 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 4115 | { |
| 4116 | struct alt_tab_preview *preview, *next; |
| 4117 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 4118 | |
| 4119 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 4120 | preview = wl_container_of(alt_tab->current, preview, link); |
| 4121 | |
| 4122 | activate(alt_tab->shell, preview->view->surface, |
| 4123 | (struct weston_seat *) keyboard->seat); |
| 4124 | } |
| 4125 | |
| 4126 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 4127 | wl_list_remove(&preview->link); |
| 4128 | wl_list_remove(&preview->listener.link); |
| 4129 | weston_view_destroy(preview->view); |
| 4130 | free(preview); |
| 4131 | } |
| 4132 | |
| 4133 | weston_keyboard_end_grab(keyboard); |
| 4134 | if (keyboard->input_method_resource) |
| 4135 | keyboard->grab = &keyboard->input_method_grab; |
| 4136 | |
| 4137 | free(alt_tab); |
| 4138 | } |
| 4139 | |
| 4140 | static void |
| 4141 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4142 | { |
| 4143 | struct alt_tab_preview *preview = |
| 4144 | container_of(listener, struct alt_tab_preview, listener); |
| 4145 | struct alt_tab *alt_tab = preview->alt_tab; |
| 4146 | int advance = 0; |
| 4147 | |
| 4148 | /* If the preview that we're removing is the currently selected one, |
| 4149 | * we want to move to the next one. So we move to ->prev and then |
| 4150 | * call _next() after removing the preview. */ |
| 4151 | if (alt_tab->current == &preview->link) { |
| 4152 | alt_tab->current = alt_tab->current->prev; |
| 4153 | advance = 1; |
| 4154 | } |
| 4155 | |
| 4156 | wl_list_remove(&preview->listener.link); |
| 4157 | wl_list_remove(&preview->link); |
| 4158 | |
| 4159 | free(preview); |
| 4160 | |
| 4161 | if (advance) |
| 4162 | alt_tab_next(alt_tab); |
| 4163 | |
| 4164 | /* If the last preview goes away, stop the alt-tab */ |
| 4165 | if (wl_list_empty(alt_tab->current)) |
| 4166 | alt_tab_destroy(alt_tab); |
| 4167 | } |
| 4168 | |
| 4169 | static void |
| 4170 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 4171 | uint32_t time, uint32_t key, uint32_t state_w) |
| 4172 | { |
| 4173 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4174 | enum wl_keyboard_key_state state = state_w; |
| 4175 | |
| 4176 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 4177 | alt_tab_next(alt_tab); |
| 4178 | } |
| 4179 | |
| 4180 | static void |
| 4181 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 4182 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4183 | uint32_t mods_locked, uint32_t group) |
| 4184 | { |
| 4185 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4186 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 4187 | |
| 4188 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 4189 | alt_tab_destroy(alt_tab); |
| 4190 | } |
| 4191 | |
| 4192 | static void |
| 4193 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 4194 | { |
| 4195 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4196 | |
| 4197 | alt_tab_destroy(alt_tab); |
| 4198 | } |
| 4199 | |
| 4200 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 4201 | alt_tab_key, |
| 4202 | alt_tab_modifier, |
| 4203 | alt_tab_cancel, |
| 4204 | }; |
| 4205 | |
| 4206 | static int |
| 4207 | view_for_alt_tab(struct weston_view *view) |
| 4208 | { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4209 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4210 | if (!shsurf) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4211 | return 0; |
| 4212 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4213 | if (shsurf->parent) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4214 | return 0; |
| 4215 | |
| 4216 | if (view != get_default_view(view->surface)) |
| 4217 | return 0; |
| 4218 | |
| 4219 | return 1; |
| 4220 | } |
| 4221 | |
| 4222 | static void |
| 4223 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 4224 | void *data) |
| 4225 | { |
| 4226 | struct alt_tab *alt_tab; |
| 4227 | struct desktop_shell *shell = data; |
| 4228 | struct weston_output *output = get_default_output(shell->compositor); |
| 4229 | struct workspace *ws; |
| 4230 | struct weston_view *view; |
| 4231 | int num_surfaces = 0; |
| 4232 | int x, y, side, margin; |
| 4233 | |
| 4234 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4235 | |
| 4236 | if (view_for_alt_tab(view)) |
| 4237 | num_surfaces++; |
| 4238 | } |
| 4239 | |
| 4240 | if (!num_surfaces) |
| 4241 | return; |
| 4242 | |
| 4243 | alt_tab = malloc(sizeof *alt_tab); |
| 4244 | if (!alt_tab) |
| 4245 | return; |
| 4246 | |
| 4247 | alt_tab->shell = shell; |
| 4248 | wl_list_init(&alt_tab->preview_list); |
| 4249 | alt_tab->current = &alt_tab->preview_list; |
| 4250 | |
| 4251 | restore_all_output_modes(shell->compositor); |
| 4252 | lower_fullscreen_layer(alt_tab->shell); |
| 4253 | |
| 4254 | alt_tab->grab.interface = &alt_tab_grab; |
| 4255 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 4256 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4257 | |
| 4258 | ws = get_current_workspace(shell); |
| 4259 | |
| 4260 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 4261 | * and/or add a black surrounding background à la gnome-shell */ |
| 4262 | |
| 4263 | /* Determine the size for each preview */ |
| 4264 | side = output->width / num_surfaces; |
| 4265 | if (side > 200) |
| 4266 | side = 200; |
| 4267 | margin = side / 4; |
| 4268 | side -= margin; |
| 4269 | |
| 4270 | x = margin; |
| 4271 | y = (output->height - side) / 2; |
| 4272 | |
| 4273 | /* Create a view for each surface */ |
| 4274 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4275 | struct alt_tab_preview *preview; |
| 4276 | struct weston_view *v; |
| 4277 | float scale; |
| 4278 | |
| 4279 | if (!view_for_alt_tab(view)) |
| 4280 | continue; |
| 4281 | |
| 4282 | preview = malloc(sizeof *preview); |
| 4283 | if (!preview) { |
| 4284 | alt_tab_destroy(alt_tab); |
| 4285 | return; |
| 4286 | } |
| 4287 | |
| 4288 | preview->alt_tab = alt_tab; |
| 4289 | |
| 4290 | preview->view = v = weston_view_create(view->surface); |
| 4291 | v->output = view->output; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4292 | |
| 4293 | wl_list_remove(&v->layer_link); |
| 4294 | wl_list_insert(&ws->layer.view_list, &v->layer_link); |
| 4295 | weston_view_damage_below(v); |
| 4296 | weston_surface_damage(v->surface); |
| 4297 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4298 | weston_view_set_position(v, x, y); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4299 | |
| 4300 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 4301 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 4302 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4303 | if (view->surface->width > view->surface->height) |
| 4304 | scale = side / (float) view->surface->width; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4305 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4306 | scale = side / (float) view->surface->height; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4307 | |
| 4308 | wl_list_insert(&v->geometry.transformation_list, |
| 4309 | &preview->transform.link); |
| 4310 | weston_matrix_init(&preview->transform.matrix); |
| 4311 | weston_matrix_scale(&preview->transform.matrix, |
| 4312 | scale, scale, 1.0f); |
| 4313 | |
| 4314 | weston_view_geometry_dirty(v); |
| 4315 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 4316 | |
| 4317 | /* Insert at the end of the list */ |
| 4318 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 4319 | |
| 4320 | x += side + margin; |
| 4321 | } |
| 4322 | |
| 4323 | /* Start at the second preview so a simple <alt>tab changes window. |
| 4324 | * We set `current' to the first preview and not the second because |
| 4325 | * we're going to receive a key press callback for the initial |
| 4326 | * <alt>tab which will make `current' point to the second element. */ |
| 4327 | alt_tab_next(alt_tab); |
| 4328 | } |
| 4329 | |
| 4330 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4331 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4332 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4333 | { |
| 4334 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4335 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4336 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4337 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4338 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4339 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4340 | weston_pointer_move(pointer, x, y); |
| 4341 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4342 | if (!shsurf) |
| 4343 | return; |
| 4344 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4345 | cx = 0.5f * shsurf->surface->width; |
| 4346 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4347 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4348 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4349 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4350 | r = sqrtf(dx * dx + dy * dy); |
| 4351 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4352 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4353 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4354 | |
| 4355 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4356 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4357 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4358 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4359 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4360 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4361 | |
| 4362 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4363 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4364 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4365 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4366 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4367 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4368 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4369 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4370 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4371 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4372 | wl_list_init(&shsurf->rotation.transform.link); |
| 4373 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4374 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4375 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4376 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4377 | /* We need to adjust the position of the surface |
| 4378 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4379 | cposx = shsurf->view->geometry.x + cx; |
| 4380 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4381 | dposx = rotate->center.x - cposx; |
| 4382 | dposy = rotate->center.y - cposy; |
| 4383 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4384 | weston_view_set_position(shsurf->view, |
| 4385 | shsurf->view->geometry.x + dposx, |
| 4386 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4387 | } |
| 4388 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4389 | /* Repaint implies weston_surface_update_transform(), which |
| 4390 | * lazily applies the damage due to rotation update. |
| 4391 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4392 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4396 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4397 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4398 | { |
| 4399 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4400 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4401 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4402 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4403 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4404 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4405 | if (pointer->button_count == 0 && |
| 4406 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4407 | if (shsurf) |
| 4408 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4409 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4410 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4411 | free(rotate); |
| 4412 | } |
| 4413 | } |
| 4414 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4415 | static void |
| 4416 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4417 | { |
| 4418 | struct rotate_grab *rotate = |
| 4419 | container_of(grab, struct rotate_grab, base.grab); |
| 4420 | |
| 4421 | shell_grab_end(&rotate->base); |
| 4422 | free(rotate); |
| 4423 | } |
| 4424 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4425 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4426 | noop_grab_focus, |
| 4427 | rotate_grab_motion, |
| 4428 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4429 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4430 | }; |
| 4431 | |
| 4432 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4433 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4434 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4435 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4436 | float dx, dy; |
| 4437 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4438 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4439 | rotate = malloc(sizeof *rotate); |
| 4440 | if (!rotate) |
| 4441 | return; |
| 4442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4443 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4444 | surface->surface->width * 0.5f, |
| 4445 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4446 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4447 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4448 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4449 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4450 | r = sqrtf(dx * dx + dy * dy); |
| 4451 | if (r > 20.0f) { |
| 4452 | struct weston_matrix inverse; |
| 4453 | |
| 4454 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4455 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4456 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4457 | |
| 4458 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4459 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4460 | } else { |
| 4461 | weston_matrix_init(&surface->rotation.rotation); |
| 4462 | weston_matrix_init(&rotate->rotation); |
| 4463 | } |
| 4464 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4465 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4466 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4470 | 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] | 4471 | void *data) |
| 4472 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4473 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4474 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4475 | struct shell_surface *surface; |
| 4476 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4477 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4478 | if (base_surface == NULL) |
| 4479 | return; |
| 4480 | |
| 4481 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4482 | if (surface == NULL || surface->state.fullscreen || |
| 4483 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4484 | return; |
| 4485 | |
| 4486 | surface_rotate(surface, seat); |
| 4487 | } |
| 4488 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4489 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4490 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4491 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4492 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4493 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4494 | { |
| 4495 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4496 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4497 | |
| 4498 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4499 | wl_list_for_each_reverse_safe(view, prev, |
| 4500 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4501 | layer_link) { |
| 4502 | wl_list_remove(&view->layer_link); |
| 4503 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4504 | weston_view_damage_below(view); |
| 4505 | weston_surface_damage(view->surface); |
| 4506 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4510 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4511 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4512 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4513 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4514 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4515 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4516 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4517 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4518 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4519 | main_surface = weston_surface_get_main_surface(es); |
| 4520 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4521 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4522 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4523 | state = ensure_focus_state(shell, seat); |
| 4524 | if (state == NULL) |
| 4525 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4526 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4527 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4528 | state->keyboard_focus = es; |
| 4529 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4530 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4531 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4532 | shsurf = get_shell_surface(main_surface); |
| 4533 | if (shsurf->state.fullscreen) |
| 4534 | shell_configure_fullscreen(shsurf); |
| 4535 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4536 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4537 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4538 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4539 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4540 | animate_focus_change(shell, ws, get_default_view(old_es), get_default_view(es)); |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4544 | * order as appropriate. */ |
| 4545 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4546 | } |
| 4547 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4548 | /* no-op func for checking black surface */ |
| 4549 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4550 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4551 | { |
| 4552 | } |
| 4553 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4554 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4555 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4556 | { |
| 4557 | if (es->configure == black_surface_configure) { |
| 4558 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4559 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4560 | return true; |
| 4561 | } |
| 4562 | return false; |
| 4563 | } |
| 4564 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4565 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4566 | activate_binding(struct weston_seat *seat, |
| 4567 | struct desktop_shell *shell, |
| 4568 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4569 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4570 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4571 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4572 | if (!focus) |
| 4573 | return; |
| 4574 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4575 | if (is_black_surface(focus, &main_surface)) |
| 4576 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4577 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4578 | main_surface = weston_surface_get_main_surface(focus); |
| 4579 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4580 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4581 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4582 | activate(shell, focus, seat); |
| 4583 | } |
| 4584 | |
| 4585 | static void |
| 4586 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4587 | void *data) |
| 4588 | { |
| 4589 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4590 | return; |
| 4591 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4592 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | static void |
| 4596 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4597 | { |
| 4598 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4599 | return; |
| 4600 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4601 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4605 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4606 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4607 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4608 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4609 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4610 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4611 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4612 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4613 | |
| 4614 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4615 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4616 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4617 | * toplevel layers. This way nothing else can show or receive |
| 4618 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4619 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4620 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4621 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4622 | if (shell->showing_input_panels) |
| 4623 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4624 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4625 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4626 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4627 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4628 | launch_screensaver(shell); |
| 4629 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4630 | /* TODO: disable bindings that should not work while locked. */ |
| 4631 | |
| 4632 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4633 | } |
| 4634 | |
| 4635 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4636 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4637 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4638 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4639 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4640 | return; |
| 4641 | } |
| 4642 | |
| 4643 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4644 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4645 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4646 | return; |
| 4647 | } |
| 4648 | |
| 4649 | if (shell->prepare_event_sent) |
| 4650 | return; |
| 4651 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4652 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4653 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4657 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4658 | { |
| 4659 | struct desktop_shell *shell = data; |
| 4660 | |
| 4661 | shell->fade.animation = NULL; |
| 4662 | |
| 4663 | switch (shell->fade.type) { |
| 4664 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4665 | weston_surface_destroy(shell->fade.view->surface); |
| 4666 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4667 | break; |
| 4668 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4669 | lock(shell); |
| 4670 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4671 | default: |
| 4672 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4673 | } |
| 4674 | } |
| 4675 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4676 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4677 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4678 | { |
| 4679 | struct weston_compositor *compositor = shell->compositor; |
| 4680 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4681 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4682 | |
| 4683 | surface = weston_surface_create(compositor); |
| 4684 | if (!surface) |
| 4685 | return NULL; |
| 4686 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4687 | view = weston_view_create(surface); |
| 4688 | if (!view) { |
| 4689 | weston_surface_destroy(surface); |
| 4690 | return NULL; |
| 4691 | } |
| 4692 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4693 | surface->width = 8192; |
| 4694 | surface->height = 8192; |
| 4695 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4696 | 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] | 4697 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4698 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4699 | pixman_region32_init(&surface->input); |
| 4700 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4701 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | static void |
| 4705 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4706 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4707 | float tint; |
| 4708 | |
| 4709 | switch (type) { |
| 4710 | case FADE_IN: |
| 4711 | tint = 0.0; |
| 4712 | break; |
| 4713 | case FADE_OUT: |
| 4714 | tint = 1.0; |
| 4715 | break; |
| 4716 | default: |
| 4717 | weston_log("shell: invalid fade type\n"); |
| 4718 | return; |
| 4719 | } |
| 4720 | |
| 4721 | shell->fade.type = type; |
| 4722 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4723 | if (shell->fade.view == NULL) { |
| 4724 | shell->fade.view = shell_fade_create_surface(shell); |
| 4725 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4726 | return; |
| 4727 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4728 | shell->fade.view->alpha = 1.0 - tint; |
| 4729 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4733 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4734 | else |
| 4735 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4736 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4737 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4738 | shell_fade_done, shell); |
| 4739 | } |
| 4740 | |
| 4741 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4742 | do_shell_fade_startup(void *data) |
| 4743 | { |
| 4744 | struct desktop_shell *shell = data; |
| 4745 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4746 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4747 | shell_fade(shell, FADE_IN); |
| 4748 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4749 | weston_surface_destroy(shell->fade.view->surface); |
| 4750 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4751 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4752 | } |
| 4753 | |
| 4754 | static void |
| 4755 | shell_fade_startup(struct desktop_shell *shell) |
| 4756 | { |
| 4757 | struct wl_event_loop *loop; |
| 4758 | |
| 4759 | if (!shell->fade.startup_timer) |
| 4760 | return; |
| 4761 | |
| 4762 | wl_event_source_remove(shell->fade.startup_timer); |
| 4763 | shell->fade.startup_timer = NULL; |
| 4764 | |
| 4765 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4766 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4767 | } |
| 4768 | |
| 4769 | static int |
| 4770 | fade_startup_timeout(void *data) |
| 4771 | { |
| 4772 | struct desktop_shell *shell = data; |
| 4773 | |
| 4774 | shell_fade_startup(shell); |
| 4775 | return 0; |
| 4776 | } |
| 4777 | |
| 4778 | static void |
| 4779 | shell_fade_init(struct desktop_shell *shell) |
| 4780 | { |
| 4781 | /* Make compositor output all black, and wait for the desktop-shell |
| 4782 | * client to signal it is ready, then fade in. The timer triggers a |
| 4783 | * fade-in, in case the desktop-shell client takes too long. |
| 4784 | */ |
| 4785 | |
| 4786 | struct wl_event_loop *loop; |
| 4787 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4788 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4789 | weston_log("%s: warning: fade surface already exists\n", |
| 4790 | __func__); |
| 4791 | return; |
| 4792 | } |
| 4793 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4794 | shell->fade.view = shell_fade_create_surface(shell); |
| 4795 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4796 | return; |
| 4797 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4798 | weston_view_update_transform(shell->fade.view); |
| 4799 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4800 | |
| 4801 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4802 | shell->fade.startup_timer = |
| 4803 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4804 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4805 | } |
| 4806 | |
| 4807 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4808 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4809 | { |
| 4810 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4811 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4812 | |
| 4813 | shell_fade(shell, FADE_OUT); |
| 4814 | /* lock() is called from shell_fade_done() */ |
| 4815 | } |
| 4816 | |
| 4817 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4818 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4819 | { |
| 4820 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4821 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4822 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4823 | unlock(shell); |
| 4824 | } |
| 4825 | |
| 4826 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4827 | show_input_panels(struct wl_listener *listener, void *data) |
| 4828 | { |
| 4829 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4830 | container_of(listener, struct desktop_shell, |
| 4831 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4832 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4833 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4834 | shell->text_input.surface = (struct weston_surface*)data; |
| 4835 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4836 | if (shell->showing_input_panels) |
| 4837 | return; |
| 4838 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4839 | shell->showing_input_panels = true; |
| 4840 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4841 | if (!shell->locked) |
| 4842 | wl_list_insert(&shell->panel_layer.link, |
| 4843 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4844 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4845 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4846 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4847 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4848 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4849 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4850 | &ipsurf->view->layer_link); |
| 4851 | weston_view_geometry_dirty(ipsurf->view); |
| 4852 | weston_view_update_transform(ipsurf->view); |
| 4853 | weston_surface_damage(ipsurf->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4854 | weston_slide_run(ipsurf->view, ipsurf->surface->height, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4855 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | static void |
| 4860 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4861 | { |
| 4862 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4863 | container_of(listener, struct desktop_shell, |
| 4864 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4865 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4866 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4867 | if (!shell->showing_input_panels) |
| 4868 | return; |
| 4869 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4870 | shell->showing_input_panels = false; |
| 4871 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4872 | if (!shell->locked) |
| 4873 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4874 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4875 | wl_list_for_each_safe(view, next, |
| 4876 | &shell->input_panel_layer.view_list, layer_link) |
| 4877 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4881 | update_input_panels(struct wl_listener *listener, void *data) |
| 4882 | { |
| 4883 | struct desktop_shell *shell = |
| 4884 | container_of(listener, struct desktop_shell, |
| 4885 | update_input_panel_listener); |
| 4886 | |
| 4887 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4888 | } |
| 4889 | |
| 4890 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4891 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4892 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4893 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4894 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4895 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4896 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4897 | |
| 4898 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4899 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4900 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4901 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4905 | weston_view_set_initial_position(struct weston_view *view, |
| 4906 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4907 | { |
| 4908 | struct weston_compositor *compositor = shell->compositor; |
| 4909 | int ix = 0, iy = 0; |
| 4910 | int range_x, range_y; |
| 4911 | int dx, dy, x, y, panel_height; |
| 4912 | struct weston_output *output, *target_output = NULL; |
| 4913 | struct weston_seat *seat; |
| 4914 | |
| 4915 | /* As a heuristic place the new window on the same output as the |
| 4916 | * pointer. Falling back to the output containing 0, 0. |
| 4917 | * |
| 4918 | * TODO: Do something clever for touch too? |
| 4919 | */ |
| 4920 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 4921 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4922 | ix = wl_fixed_to_int(seat->pointer->x); |
| 4923 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4924 | break; |
| 4925 | } |
| 4926 | } |
| 4927 | |
| 4928 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4929 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 4930 | target_output = output; |
| 4931 | break; |
| 4932 | } |
| 4933 | } |
| 4934 | |
| 4935 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4936 | weston_view_set_position(view, 10 + random() % 400, |
| 4937 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4938 | return; |
| 4939 | } |
| 4940 | |
| 4941 | /* Valid range within output where the surface will still be onscreen. |
| 4942 | * If this is negative it means that the surface is bigger than |
| 4943 | * output. |
| 4944 | */ |
| 4945 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4946 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4947 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4948 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4949 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4950 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4951 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4952 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4953 | dx = 0; |
| 4954 | |
| 4955 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4956 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 4957 | else |
| 4958 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4959 | |
| 4960 | x = target_output->x + dx; |
| 4961 | y = target_output->y + dy; |
| 4962 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4963 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4967 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4968 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4969 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4970 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 4971 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4972 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4973 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 4974 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4975 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4976 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4977 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4978 | if (shsurf->state.fullscreen) { |
| 4979 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 4980 | shell_map_fullscreen(shsurf); |
| 4981 | } else if (shsurf->state.maximized) { |
| 4982 | /* use surface configure to set the geometry */ |
| 4983 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 4984 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 4985 | &surf_x, &surf_y, NULL, NULL); |
| 4986 | weston_view_set_position(shsurf->view, |
| 4987 | shsurf->output->x - surf_x, |
| 4988 | shsurf->output->y + |
| 4989 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4990 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4991 | weston_view_set_initial_position(shsurf->view, shell); |
| 4992 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 4993 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 4994 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 4995 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 4996 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 4997 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4998 | weston_view_set_position(shsurf->view, |
| 4999 | shsurf->view->geometry.x + sx, |
| 5000 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5001 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5002 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5003 | default: |
| 5004 | ; |
| 5005 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5006 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5007 | /* Surface stacking order, see also activate(). */ |
| 5008 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5009 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5010 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5011 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5012 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5013 | shsurf->surface->output = shsurf->output; |
| 5014 | shsurf->view->output = shsurf->output; |
| 5015 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5016 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5017 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5018 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 5019 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 5020 | } |
| 5021 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5022 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5023 | /* XXX: xwayland's using the same fields for transient type */ |
| 5024 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5025 | if (shsurf->transient.flags == |
| 5026 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5027 | break; |
| 5028 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5029 | if (shsurf->state.relative && |
| 5030 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5031 | break; |
| 5032 | if (!shell->locked) |
| 5033 | break; |
| 5034 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 5035 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5036 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5037 | case SHELL_SURFACE_POPUP: |
| 5038 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5039 | default: |
| 5040 | break; |
| 5041 | } |
| 5042 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5043 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5044 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5045 | { |
| 5046 | switch (shell->win_animation_type) { |
| 5047 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5048 | 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] | 5049 | break; |
| 5050 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5051 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5052 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5053 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5054 | default: |
| 5055 | break; |
| 5056 | } |
| 5057 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5058 | } |
| 5059 | |
| 5060 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5061 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5062 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5063 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5064 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5065 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5066 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5067 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5068 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5069 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5070 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5071 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5072 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5073 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5074 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 5075 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5076 | mx = shsurf->output->x - surf_x; |
| 5077 | my = shsurf->output->y + |
| 5078 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 5079 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5080 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5081 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5082 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5083 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5084 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5085 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5086 | wl_list_for_each(view, &surface->views, surface_link) |
| 5087 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5088 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5089 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5090 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5091 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5092 | } |
| 5093 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5094 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5095 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5096 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5097 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5098 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5099 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5100 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5101 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5102 | if (!weston_surface_is_mapped(es) && |
| 5103 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5104 | remove_popup_grab(shsurf); |
| 5105 | } |
| 5106 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5107 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5108 | return; |
| 5109 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5110 | if ((shsurf->next_type != SHELL_SURFACE_NONE && |
| 5111 | shsurf->type != shsurf->next_type) || |
| 5112 | shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5113 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5114 | type_changed = 1; |
| 5115 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5116 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5117 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5118 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5119 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5120 | shsurf->last_width != es->width || |
| 5121 | shsurf->last_height != es->height) { |
| 5122 | shsurf->last_width = es->width; |
| 5123 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5124 | float from_x, from_y; |
| 5125 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5126 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5127 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5128 | 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] | 5129 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5130 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5131 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5132 | } |
| 5133 | } |
| 5134 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5135 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5136 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5137 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5138 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5139 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5140 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5141 | struct desktop_shell *shell = |
| 5142 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5143 | |
| 5144 | shell->child.process.pid = 0; |
| 5145 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5146 | |
| 5147 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5148 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5149 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5150 | shell->child.deathstamp = time; |
| 5151 | shell->child.deathcount = 0; |
| 5152 | } |
| 5153 | |
| 5154 | shell->child.deathcount++; |
| 5155 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5156 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5157 | return; |
| 5158 | } |
| 5159 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5160 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5161 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5162 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5163 | } |
| 5164 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5165 | static void |
| 5166 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5167 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5168 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5169 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5170 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5171 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5172 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5173 | desktop_shell_sigchld); |
| 5174 | |
| 5175 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5176 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5180 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5181 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5182 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5183 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5184 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5185 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 5186 | if (resource) |
| 5187 | wl_resource_set_implementation(resource, &shell_implementation, |
| 5188 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5189 | } |
| 5190 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5191 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 5192 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5193 | { |
| 5194 | struct desktop_shell *shell = data; |
| 5195 | struct wl_resource *resource; |
| 5196 | |
| 5197 | resource = wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 5198 | if (resource) |
| 5199 | wl_resource_set_dispatcher(resource, |
| 5200 | xdg_shell_unversioned_dispatch, |
| 5201 | NULL, shell, NULL); |
| 5202 | } |
| 5203 | |
| 5204 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5205 | unbind_desktop_shell(struct wl_resource *resource) |
| 5206 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5207 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5208 | |
| 5209 | if (shell->locked) |
| 5210 | resume_desktop(shell); |
| 5211 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5212 | shell->child.desktop_shell = NULL; |
| 5213 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5214 | } |
| 5215 | |
| 5216 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5217 | bind_desktop_shell(struct wl_client *client, |
| 5218 | void *data, uint32_t version, uint32_t id) |
| 5219 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5220 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5221 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5222 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5223 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5224 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5225 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5226 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5227 | wl_resource_set_implementation(resource, |
| 5228 | &desktop_shell_implementation, |
| 5229 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5230 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5231 | |
| 5232 | if (version < 2) |
| 5233 | shell_fade_startup(shell); |
| 5234 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5235 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5236 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5237 | |
| 5238 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5239 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5240 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5241 | } |
| 5242 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5243 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5244 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5245 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5246 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5247 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5248 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5249 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5250 | return; |
| 5251 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5252 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5253 | if (!shell->locked) |
| 5254 | return; |
| 5255 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5256 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5257 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5258 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5259 | if (wl_list_empty(&view->layer_link)) { |
| 5260 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5261 | &view->layer_link); |
| 5262 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5263 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5264 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5265 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5266 | } |
| 5267 | } |
| 5268 | |
| 5269 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5270 | screensaver_set_surface(struct wl_client *client, |
| 5271 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5272 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5273 | struct wl_resource *output_resource) |
| 5274 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5275 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5276 | struct weston_surface *surface = |
| 5277 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5278 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5279 | struct weston_view *view, *next; |
| 5280 | |
| 5281 | /* Make sure we only have one view */ |
| 5282 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5283 | weston_view_destroy(view); |
| 5284 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5285 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5286 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5287 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5288 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | static const struct screensaver_interface screensaver_implementation = { |
| 5292 | screensaver_set_surface |
| 5293 | }; |
| 5294 | |
| 5295 | static void |
| 5296 | unbind_screensaver(struct wl_resource *resource) |
| 5297 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5298 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5299 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5300 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | static void |
| 5304 | bind_screensaver(struct wl_client *client, |
| 5305 | void *data, uint32_t version, uint32_t id) |
| 5306 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5307 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5308 | struct wl_resource *resource; |
| 5309 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5310 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5311 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5312 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5313 | wl_resource_set_implementation(resource, |
| 5314 | &screensaver_implementation, |
| 5315 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5316 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5317 | return; |
| 5318 | } |
| 5319 | |
| 5320 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5321 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5322 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5323 | } |
| 5324 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5325 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5326 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5327 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5328 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 5329 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5330 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5331 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5332 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5333 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5334 | return; |
| 5335 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5336 | if (!weston_surface_is_mapped(surface)) { |
| 5337 | if (!shell->showing_input_panels) |
| 5338 | return; |
| 5339 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5340 | show_surface = 1; |
| 5341 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5342 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5343 | 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] | 5344 | |
| 5345 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5346 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 5347 | 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] | 5348 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5349 | x = ip_surface->output->x + (ip_surface->output->width - surface->width) / 2; |
| 5350 | y = ip_surface->output->y + ip_surface->output->height - surface->height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5351 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5352 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5353 | weston_view_set_position(ip_surface->view, x, y); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5354 | |
| 5355 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5356 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 5357 | &ip_surface->view->layer_link); |
| 5358 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5359 | weston_surface_damage(surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5360 | weston_slide_run(ip_surface->view, ip_surface->view->surface->height, 0, NULL, NULL); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5361 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5365 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5366 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5367 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 5368 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5369 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5370 | wl_list_remove(&input_panel_surface->link); |
| 5371 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5372 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5373 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5374 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5375 | free(input_panel_surface); |
| 5376 | } |
| 5377 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5378 | static struct input_panel_surface * |
| 5379 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5380 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5381 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5382 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5383 | } else { |
| 5384 | return NULL; |
| 5385 | } |
| 5386 | } |
| 5387 | |
| 5388 | static void |
| 5389 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 5390 | { |
| 5391 | struct input_panel_surface *ipsurface = container_of(listener, |
| 5392 | struct input_panel_surface, |
| 5393 | surface_destroy_listener); |
| 5394 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5395 | if (ipsurface->resource) { |
| 5396 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5397 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5398 | destroy_input_panel_surface(ipsurface); |
| 5399 | } |
| 5400 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5401 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5402 | static struct input_panel_surface * |
| 5403 | create_input_panel_surface(struct desktop_shell *shell, |
| 5404 | struct weston_surface *surface) |
| 5405 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5406 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5407 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5408 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 5409 | if (!input_panel_surface) |
| 5410 | return NULL; |
| 5411 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5412 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5413 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5414 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5415 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5416 | |
| 5417 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5418 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5419 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5420 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5421 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5422 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5423 | &input_panel_surface->surface_destroy_listener); |
| 5424 | |
| 5425 | wl_list_init(&input_panel_surface->link); |
| 5426 | |
| 5427 | return input_panel_surface; |
| 5428 | } |
| 5429 | |
| 5430 | static void |
| 5431 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 5432 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5433 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5434 | uint32_t position) |
| 5435 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5436 | struct input_panel_surface *input_panel_surface = |
| 5437 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5438 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5439 | |
| 5440 | wl_list_insert(&shell->input_panel.surfaces, |
| 5441 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5442 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5443 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5444 | input_panel_surface->panel = 0; |
| 5445 | } |
| 5446 | |
| 5447 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 5448 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 5449 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5450 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5451 | struct input_panel_surface *input_panel_surface = |
| 5452 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5453 | struct desktop_shell *shell = input_panel_surface->shell; |
| 5454 | |
| 5455 | wl_list_insert(&shell->input_panel.surfaces, |
| 5456 | &input_panel_surface->link); |
| 5457 | |
| 5458 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5459 | } |
| 5460 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5461 | 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] | 5462 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 5463 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5464 | }; |
| 5465 | |
| 5466 | static void |
| 5467 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 5468 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5469 | struct input_panel_surface *ipsurf = |
| 5470 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5471 | |
| 5472 | destroy_input_panel_surface(ipsurf); |
| 5473 | } |
| 5474 | |
| 5475 | static void |
| 5476 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 5477 | struct wl_resource *resource, |
| 5478 | uint32_t id, |
| 5479 | struct wl_resource *surface_resource) |
| 5480 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5481 | struct weston_surface *surface = |
| 5482 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5483 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5484 | struct input_panel_surface *ipsurf; |
| 5485 | |
| 5486 | if (get_input_panel_surface(surface)) { |
| 5487 | wl_resource_post_error(surface_resource, |
| 5488 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5489 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5490 | return; |
| 5491 | } |
| 5492 | |
| 5493 | ipsurf = create_input_panel_surface(shell, surface); |
| 5494 | if (!ipsurf) { |
| 5495 | wl_resource_post_error(surface_resource, |
| 5496 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5497 | "surface->configure already set"); |
| 5498 | return; |
| 5499 | } |
| 5500 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5501 | ipsurf->resource = |
| 5502 | wl_resource_create(client, |
| 5503 | &wl_input_panel_surface_interface, 1, id); |
| 5504 | wl_resource_set_implementation(ipsurf->resource, |
| 5505 | &input_panel_surface_implementation, |
| 5506 | ipsurf, |
| 5507 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5508 | } |
| 5509 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5510 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5511 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5512 | }; |
| 5513 | |
| 5514 | static void |
| 5515 | unbind_input_panel(struct wl_resource *resource) |
| 5516 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5517 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5518 | |
| 5519 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5520 | } |
| 5521 | |
| 5522 | static void |
| 5523 | bind_input_panel(struct wl_client *client, |
| 5524 | void *data, uint32_t version, uint32_t id) |
| 5525 | { |
| 5526 | struct desktop_shell *shell = data; |
| 5527 | struct wl_resource *resource; |
| 5528 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5529 | resource = wl_resource_create(client, |
| 5530 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5531 | |
| 5532 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5533 | wl_resource_set_implementation(resource, |
| 5534 | &input_panel_implementation, |
| 5535 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5536 | shell->input_panel.binding = resource; |
| 5537 | return; |
| 5538 | } |
| 5539 | |
| 5540 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5541 | "interface object already bound"); |
| 5542 | wl_resource_destroy(resource); |
| 5543 | } |
| 5544 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5545 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5546 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5547 | struct weston_surface *current; |
| 5548 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5549 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5550 | }; |
| 5551 | |
| 5552 | static void |
| 5553 | switcher_next(struct switcher *switcher) |
| 5554 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5555 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5556 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5557 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5558 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5559 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5560 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5561 | shsurf = get_shell_surface(view->surface); |
| 5562 | switch (shsurf->type) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5563 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5564 | if (shsurf->parent) |
| 5565 | break; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5566 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5567 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5568 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5569 | next = view->surface; |
| 5570 | prev = view->surface; |
| 5571 | view->alpha = 0.25; |
| 5572 | weston_view_geometry_dirty(view); |
| 5573 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5574 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5575 | case SHELL_SURFACE_POPUP: |
| 5576 | case SHELL_SURFACE_XWAYLAND: |
| 5577 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5578 | default: |
| 5579 | break; |
| 5580 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5581 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5582 | if (is_black_surface(view->surface, NULL)) { |
| 5583 | view->alpha = 0.25; |
| 5584 | weston_view_geometry_dirty(view); |
| 5585 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5586 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | if (next == NULL) |
| 5590 | next = first; |
| 5591 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5592 | if (next == NULL) |
| 5593 | return; |
| 5594 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5595 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5596 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5597 | |
| 5598 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5599 | wl_list_for_each(view, &next->views, surface_link) |
| 5600 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5601 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5602 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5603 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5604 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5608 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5609 | { |
| 5610 | struct switcher *switcher = |
| 5611 | container_of(listener, struct switcher, listener); |
| 5612 | |
| 5613 | switcher_next(switcher); |
| 5614 | } |
| 5615 | |
| 5616 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5617 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5618 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5619 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5620 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5621 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5622 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5623 | 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] | 5624 | if (is_focus_view(view)) |
| 5625 | continue; |
| 5626 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5627 | view->alpha = 1.0; |
| 5628 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5629 | } |
| 5630 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5631 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5632 | activate(switcher->shell, switcher->current, |
| 5633 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5634 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5635 | weston_keyboard_end_grab(keyboard); |
| 5636 | if (keyboard->input_method_resource) |
| 5637 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5638 | free(switcher); |
| 5639 | } |
| 5640 | |
| 5641 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5642 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5643 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5644 | { |
| 5645 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5646 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5647 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5648 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5649 | switcher_next(switcher); |
| 5650 | } |
| 5651 | |
| 5652 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5653 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5654 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5655 | uint32_t mods_locked, uint32_t group) |
| 5656 | { |
| 5657 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5658 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5659 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5660 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5661 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5662 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5663 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5664 | static void |
| 5665 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5666 | { |
| 5667 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5668 | |
| 5669 | switcher_destroy(switcher); |
| 5670 | } |
| 5671 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5672 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5673 | switcher_key, |
| 5674 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5675 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5676 | }; |
| 5677 | |
| 5678 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5679 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5680 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5681 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5682 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5683 | struct switcher *switcher; |
| 5684 | |
| 5685 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5686 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5687 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5688 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5689 | wl_list_init(&switcher->listener.link); |
| 5690 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5691 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5692 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5693 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5694 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5695 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5696 | switcher_next(switcher); |
| 5697 | } |
| 5698 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5699 | struct exposay_surface { |
| 5700 | struct desktop_shell *shell; |
| 5701 | struct weston_surface *surface; |
| 5702 | struct weston_view *view; |
| 5703 | struct wl_list link; |
| 5704 | |
| 5705 | int x; |
| 5706 | int y; |
| 5707 | int width; |
| 5708 | int height; |
| 5709 | double scale; |
| 5710 | |
| 5711 | int row; |
| 5712 | int column; |
| 5713 | |
| 5714 | /* The animations only apply a transformation for their own lifetime, |
| 5715 | * and don't have an option to indefinitely maintain the |
| 5716 | * transformation in a steady state - so, we apply our own once the |
| 5717 | * animation has finished. */ |
| 5718 | struct weston_transform transform; |
| 5719 | }; |
| 5720 | |
| 5721 | static void exposay_set_state(struct desktop_shell *shell, |
| 5722 | enum exposay_target_state state, |
| 5723 | struct weston_seat *seat); |
| 5724 | static void exposay_check_state(struct desktop_shell *shell); |
| 5725 | |
| 5726 | static void |
| 5727 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 5728 | { |
| 5729 | shell->exposay.in_flight++; |
| 5730 | } |
| 5731 | |
| 5732 | static void |
| 5733 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5734 | { |
| 5735 | if (--shell->exposay.in_flight > 0) |
| 5736 | return; |
| 5737 | |
| 5738 | exposay_check_state(shell); |
| 5739 | } |
| 5740 | |
| 5741 | static void |
| 5742 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5743 | { |
| 5744 | struct exposay_surface *esurface = data; |
| 5745 | |
| 5746 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5747 | &esurface->transform.link); |
| 5748 | weston_matrix_init(&esurface->transform.matrix); |
| 5749 | weston_matrix_scale(&esurface->transform.matrix, |
| 5750 | esurface->scale, esurface->scale, 1.0f); |
| 5751 | weston_matrix_translate(&esurface->transform.matrix, |
| 5752 | esurface->x - esurface->view->geometry.x, |
| 5753 | esurface->y - esurface->view->geometry.y, |
| 5754 | 0); |
| 5755 | |
| 5756 | weston_view_geometry_dirty(esurface->view); |
| 5757 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5758 | |
| 5759 | exposay_in_flight_dec(esurface->shell); |
| 5760 | } |
| 5761 | |
| 5762 | static void |
| 5763 | exposay_animate_in(struct exposay_surface *esurface) |
| 5764 | { |
| 5765 | exposay_in_flight_inc(esurface->shell); |
| 5766 | |
| 5767 | weston_move_scale_run(esurface->view, |
| 5768 | esurface->x - esurface->view->geometry.x, |
| 5769 | esurface->y - esurface->view->geometry.y, |
| 5770 | 1.0, esurface->scale, 0, |
| 5771 | exposay_animate_in_done, esurface); |
| 5772 | } |
| 5773 | |
| 5774 | static void |
| 5775 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5776 | { |
| 5777 | struct exposay_surface *esurface = data; |
| 5778 | struct desktop_shell *shell = esurface->shell; |
| 5779 | |
| 5780 | wl_list_remove(&esurface->link); |
| 5781 | free(esurface); |
| 5782 | |
| 5783 | exposay_in_flight_dec(shell); |
| 5784 | } |
| 5785 | |
| 5786 | static void |
| 5787 | exposay_animate_out(struct exposay_surface *esurface) |
| 5788 | { |
| 5789 | exposay_in_flight_inc(esurface->shell); |
| 5790 | |
| 5791 | /* Remove the static transformation set up by |
| 5792 | * exposay_transform_in_done(). */ |
| 5793 | wl_list_remove(&esurface->transform.link); |
| 5794 | weston_view_geometry_dirty(esurface->view); |
| 5795 | |
| 5796 | weston_move_scale_run(esurface->view, |
| 5797 | esurface->x - esurface->view->geometry.x, |
| 5798 | esurface->y - esurface->view->geometry.y, |
| 5799 | 1.0, esurface->scale, 1, |
| 5800 | exposay_animate_out_done, esurface); |
| 5801 | } |
| 5802 | |
| 5803 | static void |
| 5804 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5805 | struct exposay_surface *esurface) |
| 5806 | { |
| 5807 | struct weston_view *view = NULL; |
| 5808 | |
| 5809 | if (esurface) { |
| 5810 | shell->exposay.row_current = esurface->row; |
| 5811 | shell->exposay.column_current = esurface->column; |
| 5812 | view = esurface->view; |
| 5813 | } |
| 5814 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5815 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5816 | shell->exposay.focus_current = view; |
| 5817 | } |
| 5818 | |
| 5819 | static int |
| 5820 | exposay_is_animating(struct desktop_shell *shell) |
| 5821 | { |
| 5822 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5823 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5824 | return 0; |
| 5825 | |
| 5826 | return (shell->exposay.in_flight > 0); |
| 5827 | } |
| 5828 | |
| 5829 | static void |
| 5830 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5831 | { |
| 5832 | struct exposay_surface *esurface; |
| 5833 | |
| 5834 | if (exposay_is_animating(shell)) |
| 5835 | return; |
| 5836 | |
| 5837 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5838 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5839 | continue; |
| 5840 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5841 | continue; |
| 5842 | |
| 5843 | exposay_highlight_surface(shell, esurface); |
| 5844 | return; |
| 5845 | } |
| 5846 | } |
| 5847 | |
| 5848 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5849 | * aspect ratio into account really. Also needs to be notified of surface |
| 5850 | * addition and removal and adjust layout/animate accordingly. */ |
| 5851 | static enum exposay_layout_state |
| 5852 | exposay_layout(struct desktop_shell *shell) |
| 5853 | { |
| 5854 | struct workspace *workspace = shell->exposay.workspace; |
| 5855 | struct weston_compositor *compositor = shell->compositor; |
| 5856 | struct weston_output *output = get_default_output(compositor); |
| 5857 | struct weston_view *view; |
| 5858 | struct exposay_surface *esurface; |
| 5859 | int w, h; |
| 5860 | int i; |
| 5861 | int last_row_removed = 0; |
| 5862 | |
| 5863 | wl_list_init(&shell->exposay.surface_list); |
| 5864 | |
| 5865 | shell->exposay.num_surfaces = 0; |
| 5866 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5867 | if (!get_shell_surface(view->surface)) |
| 5868 | continue; |
| 5869 | shell->exposay.num_surfaces++; |
| 5870 | } |
| 5871 | |
| 5872 | if (shell->exposay.num_surfaces == 0) { |
| 5873 | shell->exposay.grid_size = 0; |
| 5874 | shell->exposay.hpadding_outer = 0; |
| 5875 | shell->exposay.vpadding_outer = 0; |
| 5876 | shell->exposay.padding_inner = 0; |
| 5877 | shell->exposay.surface_size = 0; |
| 5878 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5879 | } |
| 5880 | |
| 5881 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5882 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5883 | * around the outside and 80px internal padding between surfaces, and |
| 5884 | * maximise the area made available to surfaces after this, but only |
| 5885 | * to a maximum of 1/3rd the total output size. |
| 5886 | * |
| 5887 | * If we can't make a square grid, add one extra row at the bottom |
| 5888 | * which will have a smaller number of columns. |
| 5889 | * |
| 5890 | * XXX: Surely there has to be a better way to express this maths, |
| 5891 | * right?! |
| 5892 | */ |
| 5893 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5894 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5895 | shell->exposay.grid_size++; |
| 5896 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5897 | |
| 5898 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5899 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5900 | shell->exposay.padding_inner = 80; |
| 5901 | |
| 5902 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5903 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5904 | w /= shell->exposay.grid_size; |
| 5905 | |
| 5906 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5907 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5908 | h /= shell->exposay.grid_size; |
| 5909 | |
| 5910 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5911 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5912 | shell->exposay.surface_size = output->width / 2; |
| 5913 | if (shell->exposay.surface_size > (output->height / 2)) |
| 5914 | shell->exposay.surface_size = output->height / 2; |
| 5915 | |
| 5916 | i = 0; |
| 5917 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5918 | int pad; |
| 5919 | |
| 5920 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 5921 | |
| 5922 | if (!get_shell_surface(view->surface)) |
| 5923 | continue; |
| 5924 | |
| 5925 | esurface = malloc(sizeof(*esurface)); |
| 5926 | if (!esurface) { |
| 5927 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 5928 | shell->exposay.seat); |
| 5929 | break; |
| 5930 | } |
| 5931 | |
| 5932 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 5933 | esurface->shell = shell; |
| 5934 | esurface->view = view; |
| 5935 | |
| 5936 | esurface->row = i / shell->exposay.grid_size; |
| 5937 | esurface->column = i % shell->exposay.grid_size; |
| 5938 | |
| 5939 | esurface->x = shell->exposay.hpadding_outer; |
| 5940 | esurface->x += pad * esurface->column; |
| 5941 | esurface->y = shell->exposay.vpadding_outer; |
| 5942 | esurface->y += pad * esurface->row; |
| 5943 | |
| 5944 | if (esurface->row == shell->exposay.grid_size - 1) |
| 5945 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 5946 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5947 | if (view->surface->width > view->surface->height) |
| 5948 | esurface->scale = shell->exposay.surface_size / (float) view->surface->width; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5949 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5950 | esurface->scale = shell->exposay.surface_size / (float) view->surface->height; |
| 5951 | esurface->width = view->surface->width * esurface->scale; |
| 5952 | esurface->height = view->surface->height * esurface->scale; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5953 | |
| 5954 | if (shell->exposay.focus_current == esurface->view) |
| 5955 | exposay_highlight_surface(shell, esurface); |
| 5956 | |
| 5957 | exposay_animate_in(esurface); |
| 5958 | |
| 5959 | i++; |
| 5960 | } |
| 5961 | |
| 5962 | weston_compositor_schedule_repaint(shell->compositor); |
| 5963 | |
| 5964 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 5965 | } |
| 5966 | |
| 5967 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5968 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 5969 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5970 | { |
| 5971 | struct desktop_shell *shell = |
| 5972 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5973 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 5974 | weston_pointer_move(grab->pointer, x, y); |
| 5975 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5976 | exposay_pick(shell, |
| 5977 | wl_fixed_to_int(grab->pointer->x), |
| 5978 | wl_fixed_to_int(grab->pointer->y)); |
| 5979 | } |
| 5980 | |
| 5981 | static void |
| 5982 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 5983 | uint32_t state_w) |
| 5984 | { |
| 5985 | struct desktop_shell *shell = |
| 5986 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 5987 | struct weston_seat *seat = grab->pointer->seat; |
| 5988 | enum wl_pointer_button_state state = state_w; |
| 5989 | |
| 5990 | if (button != BTN_LEFT) |
| 5991 | return; |
| 5992 | |
| 5993 | /* Store the surface we clicked on, and don't do anything if we end up |
| 5994 | * releasing on a different surface. */ |
| 5995 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 5996 | shell->exposay.clicked = shell->exposay.focus_current; |
| 5997 | return; |
| 5998 | } |
| 5999 | |
| 6000 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 6001 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 6002 | else |
| 6003 | shell->exposay.clicked = NULL; |
| 6004 | } |
| 6005 | |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 6006 | static void |
| 6007 | exposay_pointer_grab_cancel(struct weston_pointer_grab *grab) |
| 6008 | { |
| 6009 | struct desktop_shell *shell = |
| 6010 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 6011 | |
| 6012 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 6013 | } |
| 6014 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6015 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 6016 | noop_grab_focus, |
| 6017 | exposay_motion, |
| 6018 | exposay_button, |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 6019 | exposay_pointer_grab_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6020 | }; |
| 6021 | |
| 6022 | static int |
| 6023 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 6024 | { |
| 6025 | struct exposay_surface *esurface; |
| 6026 | |
| 6027 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 6028 | if (esurface->row != row || esurface->column != column) |
| 6029 | continue; |
| 6030 | |
| 6031 | exposay_highlight_surface(shell, esurface); |
| 6032 | return 1; |
| 6033 | } |
| 6034 | |
| 6035 | return 0; |
| 6036 | } |
| 6037 | |
| 6038 | static void |
| 6039 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 6040 | uint32_t state_w) |
| 6041 | { |
| 6042 | struct weston_seat *seat = grab->keyboard->seat; |
| 6043 | struct desktop_shell *shell = |
| 6044 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 6045 | enum wl_keyboard_key_state state = state_w; |
| 6046 | |
| 6047 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 6048 | return; |
| 6049 | |
| 6050 | switch (key) { |
| 6051 | case KEY_ESC: |
| 6052 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 6053 | break; |
| 6054 | case KEY_ENTER: |
| 6055 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 6056 | break; |
| 6057 | case KEY_UP: |
| 6058 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 6059 | shell->exposay.column_current); |
| 6060 | break; |
| 6061 | case KEY_DOWN: |
| 6062 | /* Special case for trying to move to the bottom row when it |
| 6063 | * has fewer items than all the others. */ |
| 6064 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 6065 | shell->exposay.column_current) && |
| 6066 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 6067 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 6068 | (shell->exposay.num_surfaces % |
| 6069 | shell->exposay.grid_size) - 1); |
| 6070 | } |
| 6071 | break; |
| 6072 | case KEY_LEFT: |
| 6073 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 6074 | shell->exposay.column_current - 1); |
| 6075 | break; |
| 6076 | case KEY_RIGHT: |
| 6077 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 6078 | shell->exposay.column_current + 1); |
| 6079 | break; |
| 6080 | case KEY_TAB: |
| 6081 | /* Try to move right, then down (and to the leftmost column), |
| 6082 | * then if all else fails, to the top left. */ |
| 6083 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 6084 | shell->exposay.column_current + 1) && |
| 6085 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 6086 | exposay_maybe_move(shell, 0, 0); |
| 6087 | break; |
| 6088 | default: |
| 6089 | break; |
| 6090 | } |
| 6091 | } |
| 6092 | |
| 6093 | static void |
| 6094 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 6095 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6096 | uint32_t mods_locked, uint32_t group) |
| 6097 | { |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 6098 | struct desktop_shell *shell = |
| 6099 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 6100 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 6101 | |
| 6102 | /* We want to know when mod has been pressed and released. |
| 6103 | * FIXME: There is a problem here: if mod is pressed, then a key |
| 6104 | * is pressed and released, then mod is released, we will treat that |
| 6105 | * as if only mod had been pressed and released. */ |
| 6106 | if (seat->modifier_state) { |
| 6107 | if (seat->modifier_state == shell->binding_modifier) { |
| 6108 | shell->exposay.mod_pressed = true; |
| 6109 | } else { |
| 6110 | shell->exposay.mod_invalid = true; |
| 6111 | } |
| 6112 | } else { |
| 6113 | if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid) |
| 6114 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 6115 | |
| 6116 | shell->exposay.mod_invalid = false; |
| 6117 | shell->exposay.mod_pressed = false; |
| 6118 | } |
| 6119 | |
| 6120 | return; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6121 | } |
| 6122 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 6123 | static void |
| 6124 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 6125 | { |
| 6126 | struct desktop_shell *shell = |
| 6127 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 6128 | |
| 6129 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 6130 | } |
| 6131 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6132 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 6133 | exposay_key, |
| 6134 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 6135 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6136 | }; |
| 6137 | |
| 6138 | /** |
| 6139 | * Called when the transition from overview -> inactive has completed. |
| 6140 | */ |
| 6141 | static enum exposay_layout_state |
| 6142 | exposay_set_inactive(struct desktop_shell *shell) |
| 6143 | { |
| 6144 | struct weston_seat *seat = shell->exposay.seat; |
| 6145 | |
| 6146 | weston_keyboard_end_grab(seat->keyboard); |
| 6147 | weston_pointer_end_grab(seat->pointer); |
| 6148 | if (seat->keyboard->input_method_resource) |
| 6149 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 6150 | |
| 6151 | return EXPOSAY_LAYOUT_INACTIVE; |
| 6152 | } |
| 6153 | |
| 6154 | /** |
| 6155 | * Begins the transition from overview to inactive. */ |
| 6156 | static enum exposay_layout_state |
| 6157 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 6158 | { |
| 6159 | struct exposay_surface *esurface; |
| 6160 | |
| 6161 | /* Call activate() before we start the animations to avoid |
| 6162 | * animating back the old state and then immediately transitioning |
| 6163 | * to the new. */ |
| 6164 | if (switch_focus && shell->exposay.focus_current) |
| 6165 | activate(shell, shell->exposay.focus_current->surface, |
| 6166 | shell->exposay.seat); |
| 6167 | else if (shell->exposay.focus_prev) |
| 6168 | activate(shell, shell->exposay.focus_prev->surface, |
| 6169 | shell->exposay.seat); |
| 6170 | |
| 6171 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 6172 | exposay_animate_out(esurface); |
| 6173 | weston_compositor_schedule_repaint(shell->compositor); |
| 6174 | |
| 6175 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 6176 | } |
| 6177 | |
| 6178 | static enum exposay_layout_state |
| 6179 | exposay_transition_active(struct desktop_shell *shell) |
| 6180 | { |
| 6181 | struct weston_seat *seat = shell->exposay.seat; |
| 6182 | |
| 6183 | shell->exposay.workspace = get_current_workspace(shell); |
| 6184 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 6185 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 6186 | shell->exposay.clicked = NULL; |
| 6187 | wl_list_init(&shell->exposay.surface_list); |
| 6188 | |
| 6189 | lower_fullscreen_layer(shell); |
| 6190 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 6191 | weston_keyboard_start_grab(seat->keyboard, |
| 6192 | &shell->exposay.grab_kbd); |
| 6193 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 6194 | |
| 6195 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 6196 | weston_pointer_start_grab(seat->pointer, |
| 6197 | &shell->exposay.grab_ptr); |
| 6198 | weston_pointer_set_focus(seat->pointer, NULL, |
| 6199 | seat->pointer->x, seat->pointer->y); |
| 6200 | |
| 6201 | return exposay_layout(shell); |
| 6202 | } |
| 6203 | |
| 6204 | static void |
| 6205 | exposay_check_state(struct desktop_shell *shell) |
| 6206 | { |
| 6207 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 6208 | int do_switch = 0; |
| 6209 | |
| 6210 | /* Don't do anything whilst animations are running, just store up |
| 6211 | * target state changes and only act on them when the animations have |
| 6212 | * completed. */ |
| 6213 | if (exposay_is_animating(shell)) |
| 6214 | return; |
| 6215 | |
| 6216 | switch (shell->exposay.state_target) { |
| 6217 | case EXPOSAY_TARGET_OVERVIEW: |
| 6218 | switch (shell->exposay.state_cur) { |
| 6219 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 6220 | goto out; |
| 6221 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 6222 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 6223 | break; |
| 6224 | default: |
| 6225 | state_new = exposay_transition_active(shell); |
| 6226 | break; |
| 6227 | } |
| 6228 | break; |
| 6229 | |
| 6230 | case EXPOSAY_TARGET_SWITCH: |
| 6231 | do_switch = 1; /* fallthrough */ |
| 6232 | case EXPOSAY_TARGET_CANCEL: |
| 6233 | switch (shell->exposay.state_cur) { |
| 6234 | case EXPOSAY_LAYOUT_INACTIVE: |
| 6235 | goto out; |
| 6236 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 6237 | state_new = exposay_set_inactive(shell); |
| 6238 | break; |
| 6239 | default: |
| 6240 | state_new = exposay_transition_inactive(shell, do_switch); |
| 6241 | break; |
| 6242 | } |
| 6243 | |
| 6244 | break; |
| 6245 | } |
| 6246 | |
| 6247 | out: |
| 6248 | shell->exposay.state_cur = state_new; |
| 6249 | } |
| 6250 | |
| 6251 | static void |
| 6252 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 6253 | struct weston_seat *seat) |
| 6254 | { |
| 6255 | shell->exposay.state_target = state; |
| 6256 | shell->exposay.seat = seat; |
| 6257 | exposay_check_state(shell); |
| 6258 | } |
| 6259 | |
| 6260 | static void |
| 6261 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 6262 | void *data) |
| 6263 | { |
| 6264 | struct desktop_shell *shell = data; |
| 6265 | |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 6266 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6267 | } |
| 6268 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6269 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6270 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6271 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6272 | { |
| 6273 | struct weston_compositor *compositor = data; |
| 6274 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6275 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6276 | |
| 6277 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6278 | * control on the primary display. We'd have to extend later if we |
| 6279 | * ever get support for setting backlights on random desktop LCD |
| 6280 | * panels though */ |
| 6281 | output = get_default_output(compositor); |
| 6282 | if (!output) |
| 6283 | return; |
| 6284 | |
| 6285 | if (!output->set_backlight) |
| 6286 | return; |
| 6287 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6288 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6289 | backlight_new = output->backlight_current - 25; |
| 6290 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6291 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6292 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6293 | if (backlight_new < 5) |
| 6294 | backlight_new = 5; |
| 6295 | if (backlight_new > 255) |
| 6296 | backlight_new = 255; |
| 6297 | |
| 6298 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6299 | output->set_backlight(output, output->backlight_current); |
| 6300 | } |
| 6301 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6302 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6303 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6304 | struct weston_seat *seat; |
| 6305 | uint32_t key[2]; |
| 6306 | int key_released[2]; |
| 6307 | }; |
| 6308 | |
| 6309 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6310 | 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] | 6311 | uint32_t key, uint32_t state) |
| 6312 | { |
| 6313 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 6314 | struct weston_compositor *ec = db->seat->compositor; |
| 6315 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6316 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6317 | uint32_t serial; |
| 6318 | int send = 0, terminate = 0; |
| 6319 | int check_binding = 1; |
| 6320 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6321 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6322 | |
| 6323 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 6324 | /* Do not run bindings on key releases */ |
| 6325 | check_binding = 0; |
| 6326 | |
| 6327 | for (i = 0; i < 2; i++) |
| 6328 | if (key == db->key[i]) |
| 6329 | db->key_released[i] = 1; |
| 6330 | |
| 6331 | if (db->key_released[0] && db->key_released[1]) { |
| 6332 | /* All key releases been swalled so end the grab */ |
| 6333 | terminate = 1; |
| 6334 | } else if (key != db->key[0] && key != db->key[1]) { |
| 6335 | /* Should not swallow release of other keys */ |
| 6336 | send = 1; |
| 6337 | } |
| 6338 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 6339 | /* Do not check bindings for the first press of the binding |
| 6340 | * key. This allows it to be used as a debug shortcut. |
| 6341 | * We still need to swallow this event. */ |
| 6342 | check_binding = 0; |
| 6343 | } else if (db->key[1]) { |
| 6344 | /* If we already ran a binding don't process another one since |
| 6345 | * we can't keep track of all the binding keys that were |
| 6346 | * pressed in order to swallow the release events. */ |
| 6347 | send = 1; |
| 6348 | check_binding = 0; |
| 6349 | } |
| 6350 | |
| 6351 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6352 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 6353 | key, state)) { |
| 6354 | /* We ran a binding so swallow the press and keep the |
| 6355 | * grab to swallow the released too. */ |
| 6356 | send = 0; |
| 6357 | terminate = 0; |
| 6358 | db->key[1] = key; |
| 6359 | } else { |
| 6360 | /* Terminate the grab since the key pressed is not a |
| 6361 | * debug binding key. */ |
| 6362 | send = 1; |
| 6363 | terminate = 1; |
| 6364 | } |
| 6365 | } |
| 6366 | |
| 6367 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6368 | serial = wl_display_next_serial(display); |
| 6369 | resource_list = &grab->keyboard->focus_resource_list; |
| 6370 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6371 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 6372 | } |
| 6373 | } |
| 6374 | |
| 6375 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6376 | weston_keyboard_end_grab(grab->keyboard); |
| 6377 | if (grab->keyboard->input_method_resource) |
| 6378 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6379 | free(db); |
| 6380 | } |
| 6381 | } |
| 6382 | |
| 6383 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6384 | 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] | 6385 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6386 | uint32_t mods_locked, uint32_t group) |
| 6387 | { |
| 6388 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6389 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6390 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6391 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6392 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6393 | wl_resource_for_each(resource, resource_list) { |
| 6394 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 6395 | mods_latched, mods_locked, group); |
| 6396 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6397 | } |
| 6398 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6399 | static void |
| 6400 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 6401 | { |
| 6402 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 6403 | |
| 6404 | weston_keyboard_end_grab(grab->keyboard); |
| 6405 | free(db); |
| 6406 | } |
| 6407 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6408 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6409 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6410 | debug_binding_modifiers, |
| 6411 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6412 | }; |
| 6413 | |
| 6414 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6415 | 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] | 6416 | { |
| 6417 | struct debug_binding_grab *grab; |
| 6418 | |
| 6419 | grab = calloc(1, sizeof *grab); |
| 6420 | if (!grab) |
| 6421 | return; |
| 6422 | |
| 6423 | grab->seat = (struct weston_seat *) seat; |
| 6424 | grab->key[0] = key; |
| 6425 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6426 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6427 | } |
| 6428 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6429 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6430 | 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] | 6431 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6432 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6433 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6434 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6435 | struct desktop_shell *shell = data; |
| 6436 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6437 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6438 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6439 | focus_surface = seat->keyboard->focus; |
| 6440 | if (!focus_surface) |
| 6441 | return; |
| 6442 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6443 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6444 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6445 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6446 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6447 | |
| 6448 | /* Skip clients that we launched ourselves (the credentials of |
| 6449 | * the socketpair is ours) */ |
| 6450 | if (pid == getpid()) |
| 6451 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6452 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6453 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6454 | } |
| 6455 | |
| 6456 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6457 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6458 | uint32_t key, void *data) |
| 6459 | { |
| 6460 | struct desktop_shell *shell = data; |
| 6461 | unsigned int new_index = shell->workspaces.current; |
| 6462 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6463 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6464 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6465 | if (new_index != 0) |
| 6466 | new_index--; |
| 6467 | |
| 6468 | change_workspace(shell, new_index); |
| 6469 | } |
| 6470 | |
| 6471 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6472 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6473 | uint32_t key, void *data) |
| 6474 | { |
| 6475 | struct desktop_shell *shell = data; |
| 6476 | unsigned int new_index = shell->workspaces.current; |
| 6477 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6478 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6479 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6480 | if (new_index < shell->workspaces.num - 1) |
| 6481 | new_index++; |
| 6482 | |
| 6483 | change_workspace(shell, new_index); |
| 6484 | } |
| 6485 | |
| 6486 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6487 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6488 | uint32_t key, void *data) |
| 6489 | { |
| 6490 | struct desktop_shell *shell = data; |
| 6491 | unsigned int new_index; |
| 6492 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6493 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6494 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6495 | new_index = key - KEY_F1; |
| 6496 | if (new_index >= shell->workspaces.num) |
| 6497 | new_index = shell->workspaces.num - 1; |
| 6498 | |
| 6499 | change_workspace(shell, new_index); |
| 6500 | } |
| 6501 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6502 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6503 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6504 | uint32_t key, void *data) |
| 6505 | { |
| 6506 | struct desktop_shell *shell = data; |
| 6507 | unsigned int new_index = shell->workspaces.current; |
| 6508 | |
| 6509 | if (shell->locked) |
| 6510 | return; |
| 6511 | |
| 6512 | if (new_index != 0) |
| 6513 | new_index--; |
| 6514 | |
| 6515 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6516 | } |
| 6517 | |
| 6518 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6519 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6520 | uint32_t key, void *data) |
| 6521 | { |
| 6522 | struct desktop_shell *shell = data; |
| 6523 | unsigned int new_index = shell->workspaces.current; |
| 6524 | |
| 6525 | if (shell->locked) |
| 6526 | return; |
| 6527 | |
| 6528 | if (new_index < shell->workspaces.num - 1) |
| 6529 | new_index++; |
| 6530 | |
| 6531 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6532 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6533 | |
| 6534 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6535 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6536 | { |
| 6537 | struct shell_output *output_listener = |
| 6538 | container_of(listener, struct shell_output, destroy_listener); |
| 6539 | |
| 6540 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6541 | wl_list_remove(&output_listener->link); |
| 6542 | free(output_listener); |
| 6543 | } |
| 6544 | |
| 6545 | static void |
| 6546 | create_shell_output(struct desktop_shell *shell, |
| 6547 | struct weston_output *output) |
| 6548 | { |
| 6549 | struct shell_output *shell_output; |
| 6550 | |
| 6551 | shell_output = zalloc(sizeof *shell_output); |
| 6552 | if (shell_output == NULL) |
| 6553 | return; |
| 6554 | |
| 6555 | shell_output->output = output; |
| 6556 | shell_output->shell = shell; |
| 6557 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6558 | wl_signal_add(&output->destroy_signal, |
| 6559 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6560 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6561 | } |
| 6562 | |
| 6563 | static void |
| 6564 | handle_output_create(struct wl_listener *listener, void *data) |
| 6565 | { |
| 6566 | struct desktop_shell *shell = |
| 6567 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6568 | struct weston_output *output = (struct weston_output *)data; |
| 6569 | |
| 6570 | create_shell_output(shell, output); |
| 6571 | } |
| 6572 | |
| 6573 | static void |
| 6574 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6575 | struct desktop_shell *shell) |
| 6576 | { |
| 6577 | struct weston_output *output; |
| 6578 | |
| 6579 | wl_list_init(&shell->output_list); |
| 6580 | wl_list_for_each(output, &ec->output_list, link) |
| 6581 | create_shell_output(shell, output); |
| 6582 | |
| 6583 | shell->output_create_listener.notify = handle_output_create; |
| 6584 | wl_signal_add(&ec->output_created_signal, |
| 6585 | &shell->output_create_listener); |
| 6586 | } |
| 6587 | |
| 6588 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6589 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6590 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6591 | struct desktop_shell *shell = |
| 6592 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6593 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6594 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6595 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6596 | if (shell->child.client) |
| 6597 | wl_client_destroy(shell->child.client); |
| 6598 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6599 | wl_list_remove(&shell->idle_listener.link); |
| 6600 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6601 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 6602 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6603 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6604 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6605 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6606 | wl_list_remove(&shell_output->link); |
| 6607 | free(shell_output); |
| 6608 | } |
| 6609 | |
| 6610 | wl_list_remove(&shell->output_create_listener.link); |
| 6611 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6612 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6613 | workspace_destroy(*ws); |
| 6614 | wl_array_release(&shell->workspaces.array); |
| 6615 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6616 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6617 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6618 | free(shell); |
| 6619 | } |
| 6620 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6621 | static void |
| 6622 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6623 | { |
| 6624 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6625 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6626 | |
| 6627 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6628 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6629 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6630 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 6631 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 6632 | MODIFIER_ALT, |
| 6633 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6634 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6635 | click_to_activate_binding, |
| 6636 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6637 | weston_compositor_add_touch_binding(ec, 0, |
| 6638 | touch_to_activate_binding, |
| 6639 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6640 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6641 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6642 | surface_opacity_binding, NULL); |
| 6643 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6644 | MODIFIER_SUPER, zoom_axis_binding, |
| 6645 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6646 | |
| 6647 | /* configurable bindings */ |
| 6648 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6649 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6650 | zoom_key_binding, NULL); |
| 6651 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6652 | zoom_key_binding, NULL); |
| 6653 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6654 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6655 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6656 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6657 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6658 | |
| 6659 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6660 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6661 | rotate_binding, NULL); |
| 6662 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6663 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6664 | shell); |
| 6665 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6666 | ec); |
| 6667 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6668 | backlight_binding, ec); |
| 6669 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6670 | ec); |
| 6671 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6672 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6673 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6674 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6675 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6676 | workspace_up_binding, shell); |
| 6677 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6678 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6679 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6680 | workspace_move_surface_up_binding, |
| 6681 | shell); |
| 6682 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6683 | workspace_move_surface_down_binding, |
| 6684 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6685 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6686 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 6687 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6688 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6689 | if (shell->workspaces.num > 1) { |
| 6690 | num_workspace_bindings = shell->workspaces.num; |
| 6691 | if (num_workspace_bindings > 6) |
| 6692 | num_workspace_bindings = 6; |
| 6693 | for (i = 0; i < num_workspace_bindings; i++) |
| 6694 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6695 | workspace_f_binding, |
| 6696 | shell); |
| 6697 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6698 | |
| 6699 | /* Debug bindings */ |
| 6700 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6701 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6702 | } |
| 6703 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6704 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6705 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6706 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6707 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6708 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6709 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6710 | struct workspace **pws; |
| 6711 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6712 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6713 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6714 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6715 | if (shell == NULL) |
| 6716 | return -1; |
| 6717 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6718 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6719 | |
| 6720 | shell->destroy_listener.notify = shell_destroy; |
| 6721 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6722 | shell->idle_listener.notify = idle_handler; |
| 6723 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6724 | shell->wake_listener.notify = wake_handler; |
| 6725 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6726 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6727 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6728 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6729 | 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] | 6730 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6731 | 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] | 6732 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6733 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6734 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6735 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6736 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6737 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6738 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6739 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6740 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6741 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6742 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6743 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6744 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6745 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6746 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6747 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6748 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6749 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6750 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6751 | |
| 6752 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6753 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6754 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6755 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6756 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6757 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6758 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6759 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6760 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6761 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6762 | if (pws == NULL) |
| 6763 | return -1; |
| 6764 | |
| 6765 | *pws = workspace_create(); |
| 6766 | if (*pws == NULL) |
| 6767 | return -1; |
| 6768 | } |
| 6769 | activate_workspace(shell, 0); |
| 6770 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6771 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6772 | wl_list_init(&shell->workspaces.animation.link); |
| 6773 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6774 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6775 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6776 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6777 | return -1; |
| 6778 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame^] | 6779 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6780 | shell, bind_xdg_shell) == NULL) |
| 6781 | return -1; |
| 6782 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6783 | if (wl_global_create(ec->wl_display, |
| 6784 | &desktop_shell_interface, 2, |
| 6785 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6786 | return -1; |
| 6787 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6788 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6789 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6790 | return -1; |
| 6791 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6792 | 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] | 6793 | shell, bind_input_panel) == NULL) |
| 6794 | return -1; |
| 6795 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6796 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6797 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6798 | return -1; |
| 6799 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6800 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6801 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6802 | setup_output_destroy_handler(ec, shell); |
| 6803 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6804 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6805 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6806 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6807 | shell->screensaver.timer = |
| 6808 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6809 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6810 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6811 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6812 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6813 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6814 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6815 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6816 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6817 | return 0; |
| 6818 | } |