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; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 306 | int32_t saved_width, saved_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 307 | bool saved_position_valid; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 308 | bool saved_size_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 309 | bool saved_rotation_valid; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 310 | int unresponsive, grabbed; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 311 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 312 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 313 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 314 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 315 | } rotation; |
| 316 | |
| 317 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 318 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 319 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 320 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 321 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 322 | } popup; |
| 323 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 324 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 325 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 326 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 327 | } transient; |
| 328 | |
| 329 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 330 | enum wl_shell_surface_fullscreen_method type; |
| 331 | struct weston_transform transform; /* matrix from x, y */ |
| 332 | uint32_t framerate; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 333 | struct weston_view *black_view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 334 | } fullscreen; |
| 335 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 336 | struct ping_timer *ping_timer; |
| 337 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 338 | struct weston_transform workspace_transform; |
| 339 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 340 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 341 | struct weston_output *output; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 342 | struct weston_output *recommended_output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 343 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 344 | |
| 345 | const struct weston_shell_client *client; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 346 | |
| 347 | struct { |
| 348 | bool maximized; |
| 349 | bool fullscreen; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 350 | bool relative; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 351 | } state, next_state; /* surface states */ |
| 352 | bool state_changed; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 353 | }; |
| 354 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 355 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 356 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 357 | struct shell_surface *shsurf; |
| 358 | struct wl_listener shsurf_destroy_listener; |
| 359 | }; |
| 360 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 361 | struct shell_touch_grab { |
| 362 | struct weston_touch_grab grab; |
| 363 | struct shell_surface *shsurf; |
| 364 | struct wl_listener shsurf_destroy_listener; |
| 365 | struct weston_touch *touch; |
| 366 | }; |
| 367 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 368 | struct weston_move_grab { |
| 369 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 370 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 371 | }; |
| 372 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 373 | struct weston_touch_move_grab { |
| 374 | struct shell_touch_grab base; |
| 375 | wl_fixed_t dx, dy; |
| 376 | }; |
| 377 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 378 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 379 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 380 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 381 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 382 | float x; |
| 383 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 384 | } center; |
| 385 | }; |
| 386 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 387 | struct shell_seat { |
| 388 | struct weston_seat *seat; |
| 389 | struct wl_listener seat_destroy_listener; |
| 390 | |
| 391 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 392 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 393 | struct wl_list surfaces_list; |
| 394 | struct wl_client *client; |
| 395 | int32_t initial_up; |
| 396 | } popup_grab; |
| 397 | }; |
| 398 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 399 | static void |
| 400 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 401 | struct weston_seat *seat); |
| 402 | |
| 403 | static struct workspace * |
| 404 | get_current_workspace(struct desktop_shell *shell); |
| 405 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 406 | static struct shell_surface * |
| 407 | get_shell_surface(struct weston_surface *surface); |
| 408 | |
| 409 | static struct desktop_shell * |
| 410 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 411 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 412 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 413 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 414 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 415 | static void |
| 416 | shell_fade_startup(struct desktop_shell *shell); |
| 417 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 418 | static struct shell_seat * |
| 419 | get_shell_seat(struct weston_seat *seat); |
| 420 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 421 | static void |
| 422 | shell_surface_update_child_surface_layers(struct shell_surface *shsurf); |
| 423 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 424 | static bool |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 425 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf); |
| 426 | |
| 427 | static bool |
| 428 | shell_surface_is_xdg_surface(struct shell_surface *shsurf); |
| 429 | |
| 430 | static bool |
| 431 | shell_surface_is_xdg_popup(struct shell_surface *shsurf); |
| 432 | |
| 433 | static void |
| 434 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 435 | struct weston_surface *parent); |
| 436 | |
| 437 | static bool |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 438 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 439 | { |
| 440 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 441 | struct weston_view *top_fs_ev; |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 442 | |
| 443 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 444 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 445 | if (wl_list_empty(&shell->fullscreen_layer.view_list)) |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 446 | return false; |
| 447 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 448 | top_fs_ev = container_of(shell->fullscreen_layer.view_list.next, |
| 449 | struct weston_view, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 450 | layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 451 | return (shsurf == get_shell_surface(top_fs_ev->surface)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 452 | } |
| 453 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 454 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 455 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 456 | { |
| 457 | struct shell_grab *grab; |
| 458 | |
| 459 | grab = container_of(listener, struct shell_grab, |
| 460 | shsurf_destroy_listener); |
| 461 | |
| 462 | grab->shsurf = NULL; |
| 463 | } |
| 464 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 465 | static struct weston_view * |
| 466 | get_default_view(struct weston_surface *surface) |
| 467 | { |
| 468 | struct shell_surface *shsurf; |
| 469 | struct weston_view *view; |
| 470 | |
| 471 | if (!surface || wl_list_empty(&surface->views)) |
| 472 | return NULL; |
| 473 | |
| 474 | shsurf = get_shell_surface(surface); |
| 475 | if (shsurf) |
| 476 | return shsurf->view; |
| 477 | |
| 478 | wl_list_for_each(view, &surface->views, surface_link) |
| 479 | if (weston_view_is_mapped(view)) |
| 480 | return view; |
| 481 | |
| 482 | return container_of(surface->views.next, struct weston_view, surface_link); |
| 483 | } |
| 484 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 485 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 486 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 487 | |
| 488 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 489 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 490 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 491 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 492 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 493 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 494 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 495 | struct desktop_shell *shell = shsurf->shell; |
| 496 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 497 | popup_grab_end(pointer); |
| 498 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 499 | grab->grab.interface = interface; |
| 500 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 501 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 502 | wl_signal_add(&shsurf->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 503 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 504 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 505 | shsurf->grabbed = 1; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 506 | weston_pointer_start_grab(pointer, &grab->grab); |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 507 | if (shell->child.desktop_shell) { |
| 508 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, |
| 509 | cursor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 510 | weston_pointer_set_focus(pointer, |
| 511 | get_default_view(shell->grab_surface), |
Kristian Høgsberg | c9974a0 | 2013-07-03 19:24:57 -0400 | [diff] [blame] | 512 | wl_fixed_from_int(0), |
| 513 | wl_fixed_from_int(0)); |
| 514 | } |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 518 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 519 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 520 | if (grab->shsurf) { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 521 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 522 | grab->shsurf->grabbed = 0; |
| 523 | } |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 524 | |
Kristian Høgsberg | 9e5d7d1 | 2013-07-22 16:31:53 -0700 | [diff] [blame] | 525 | weston_pointer_end_grab(grab->grab.pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 529 | shell_touch_grab_start(struct shell_touch_grab *grab, |
| 530 | const struct weston_touch_grab_interface *interface, |
| 531 | struct shell_surface *shsurf, |
| 532 | struct weston_touch *touch) |
| 533 | { |
| 534 | struct desktop_shell *shell = shsurf->shell; |
| 535 | |
| 536 | grab->grab.interface = interface; |
| 537 | grab->shsurf = shsurf; |
| 538 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 539 | wl_signal_add(&shsurf->destroy_signal, |
| 540 | &grab->shsurf_destroy_listener); |
| 541 | |
| 542 | grab->touch = touch; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 543 | shsurf->grabbed = 1; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 544 | |
| 545 | weston_touch_start_grab(touch, &grab->grab); |
| 546 | if (shell->child.desktop_shell) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 547 | weston_touch_set_focus(touch->seat, |
| 548 | get_default_view(shell->grab_surface)); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static void |
| 552 | shell_touch_grab_end(struct shell_touch_grab *grab) |
| 553 | { |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 554 | if (grab->shsurf) { |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 555 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 556 | grab->shsurf->grabbed = 0; |
| 557 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 558 | |
| 559 | weston_touch_end_grab(grab->touch); |
| 560 | } |
| 561 | |
| 562 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 563 | center_on_output(struct weston_view *view, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 564 | struct weston_output *output); |
| 565 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 566 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 567 | get_modifier(char *modifier) |
| 568 | { |
| 569 | if (!modifier) |
| 570 | return MODIFIER_SUPER; |
| 571 | |
| 572 | if (!strcmp("ctrl", modifier)) |
| 573 | return MODIFIER_CTRL; |
| 574 | else if (!strcmp("alt", modifier)) |
| 575 | return MODIFIER_ALT; |
| 576 | else if (!strcmp("super", modifier)) |
| 577 | return MODIFIER_SUPER; |
| 578 | else |
| 579 | return MODIFIER_SUPER; |
| 580 | } |
| 581 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 582 | static enum animation_type |
| 583 | get_animation_type(char *animation) |
| 584 | { |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 585 | if (!strcmp("zoom", animation)) |
| 586 | return ANIMATION_ZOOM; |
| 587 | else if (!strcmp("fade", animation)) |
| 588 | return ANIMATION_FADE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 589 | else if (!strcmp("dim-layer", animation)) |
| 590 | return ANIMATION_DIM_LAYER; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 591 | else |
| 592 | return ANIMATION_NONE; |
| 593 | } |
| 594 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 595 | static void |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 596 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 597 | { |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 598 | struct weston_config_section *section; |
| 599 | int duration; |
| 600 | char *s; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 601 | |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 602 | section = weston_config_get_section(shell->compositor->config, |
| 603 | "screensaver", NULL, NULL); |
| 604 | weston_config_section_get_string(section, |
| 605 | "path", &shell->screensaver.path, NULL); |
| 606 | weston_config_section_get_int(section, "duration", &duration, 60); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 607 | shell->screensaver.duration = duration * 1000; |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 608 | |
| 609 | section = weston_config_get_section(shell->compositor->config, |
| 610 | "shell", NULL, NULL); |
| 611 | weston_config_section_get_string(section, |
Emilio Pozuelo Monfort | 8a81b83 | 2013-12-02 12:53:32 +0100 | [diff] [blame] | 612 | "client", &s, LIBEXECDIR "/" WESTON_SHELL_CLIENT); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 613 | shell->client = s; |
| 614 | weston_config_section_get_string(section, |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 615 | "binding-modifier", &s, "super"); |
| 616 | shell->binding_modifier = get_modifier(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 617 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 618 | weston_config_section_get_string(section, "animation", &s, "none"); |
| 619 | shell->win_animation_type = get_animation_type(s); |
Quentin Glidic | 8418c29 | 2013-06-18 09:11:03 +0200 | [diff] [blame] | 620 | free(s); |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 621 | weston_config_section_get_string(section, |
| 622 | "startup-animation", &s, "fade"); |
| 623 | shell->startup_animation_type = get_animation_type(s); |
| 624 | free(s); |
Kristian Høgsberg | 912e0a1 | 2013-10-30 08:59:55 -0700 | [diff] [blame] | 625 | if (shell->startup_animation_type == ANIMATION_ZOOM) |
| 626 | shell->startup_animation_type = ANIMATION_NONE; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 627 | weston_config_section_get_string(section, "focus-animation", &s, "none"); |
| 628 | shell->focus_animation_type = get_animation_type(s); |
| 629 | free(s); |
Kristian Høgsberg | 673a889 | 2013-05-23 21:40:56 -0400 | [diff] [blame] | 630 | weston_config_section_get_uint(section, "num-workspaces", |
| 631 | &shell->workspaces.num, |
| 632 | DEFAULT_NUM_WORKSPACES); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 635 | static struct weston_output * |
| 636 | get_default_output(struct weston_compositor *compositor) |
| 637 | { |
| 638 | return container_of(compositor->output_list.next, |
| 639 | struct weston_output, link); |
| 640 | } |
| 641 | |
| 642 | |
| 643 | /* no-op func for checking focus surface */ |
| 644 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 645 | 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] | 646 | { |
| 647 | } |
| 648 | |
| 649 | static struct focus_surface * |
| 650 | get_focus_surface(struct weston_surface *surface) |
| 651 | { |
| 652 | if (surface->configure == focus_surface_configure) |
| 653 | return surface->configure_private; |
| 654 | else |
| 655 | return NULL; |
| 656 | } |
| 657 | |
| 658 | static bool |
| 659 | is_focus_surface (struct weston_surface *es) |
| 660 | { |
| 661 | return (es->configure == focus_surface_configure); |
| 662 | } |
| 663 | |
| 664 | static bool |
| 665 | is_focus_view (struct weston_view *view) |
| 666 | { |
| 667 | return is_focus_surface (view->surface); |
| 668 | } |
| 669 | |
| 670 | static struct focus_surface * |
| 671 | create_focus_surface(struct weston_compositor *ec, |
| 672 | struct weston_output *output) |
| 673 | { |
| 674 | struct focus_surface *fsurf = NULL; |
| 675 | struct weston_surface *surface = NULL; |
| 676 | |
| 677 | fsurf = malloc(sizeof *fsurf); |
| 678 | if (!fsurf) |
| 679 | return NULL; |
| 680 | |
| 681 | fsurf->surface = weston_surface_create(ec); |
| 682 | surface = fsurf->surface; |
| 683 | if (surface == NULL) { |
| 684 | free(fsurf); |
| 685 | return NULL; |
| 686 | } |
| 687 | |
| 688 | surface->configure = focus_surface_configure; |
| 689 | surface->output = output; |
| 690 | surface->configure_private = fsurf; |
| 691 | |
| 692 | fsurf->view = weston_view_create (surface); |
Emilio Pozuelo Monfort | da64426 | 2013-11-19 11:37:19 +0100 | [diff] [blame] | 693 | fsurf->view->output = output; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 694 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 695 | surface->width = output->width; |
| 696 | surface->height = output->height; |
| 697 | weston_view_set_position(fsurf->view, output->x, output->y); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 698 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 699 | pixman_region32_fini(&surface->opaque); |
| 700 | pixman_region32_init_rect(&surface->opaque, output->x, output->y, |
| 701 | output->width, output->height); |
| 702 | pixman_region32_fini(&surface->input); |
| 703 | pixman_region32_init(&surface->input); |
| 704 | |
| 705 | wl_list_init(&fsurf->workspace_transform.link); |
| 706 | |
| 707 | return fsurf; |
| 708 | } |
| 709 | |
| 710 | static void |
| 711 | focus_surface_destroy(struct focus_surface *fsurf) |
| 712 | { |
| 713 | weston_surface_destroy(fsurf->surface); |
| 714 | free(fsurf); |
| 715 | } |
| 716 | |
| 717 | static void |
| 718 | focus_animation_done(struct weston_view_animation *animation, void *data) |
| 719 | { |
| 720 | struct workspace *ws = data; |
| 721 | |
| 722 | ws->focus_animation = NULL; |
| 723 | } |
| 724 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 725 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 726 | focus_state_destroy(struct focus_state *state) |
| 727 | { |
| 728 | wl_list_remove(&state->seat_destroy_listener.link); |
| 729 | wl_list_remove(&state->surface_destroy_listener.link); |
| 730 | free(state); |
| 731 | } |
| 732 | |
| 733 | static void |
| 734 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 735 | { |
| 736 | struct focus_state *state = container_of(listener, |
| 737 | struct focus_state, |
| 738 | seat_destroy_listener); |
| 739 | |
| 740 | wl_list_remove(&state->link); |
| 741 | focus_state_destroy(state); |
| 742 | } |
| 743 | |
| 744 | static void |
| 745 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 746 | { |
| 747 | struct focus_state *state = container_of(listener, |
| 748 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 749 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 750 | struct desktop_shell *shell; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 751 | struct weston_surface *main_surface, *next; |
| 752 | struct weston_view *view; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 753 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 754 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 755 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 756 | next = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 757 | wl_list_for_each(view, &state->ws->layer.view_list, layer_link) { |
| 758 | if (view->surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 759 | continue; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 760 | if (is_focus_view(view)) |
| 761 | continue; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 762 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 763 | next = view->surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 764 | break; |
| 765 | } |
| 766 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 767 | /* if the focus was a sub-surface, activate its main surface */ |
| 768 | if (main_surface != state->keyboard_focus) |
| 769 | next = main_surface; |
| 770 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 771 | shell = state->seat->compositor->shell_interface.shell; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 772 | if (next) { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 773 | state->keyboard_focus = NULL; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 774 | activate(shell, next, state->seat); |
| 775 | } else { |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 776 | if (shell->focus_animation_type == ANIMATION_DIM_LAYER) { |
| 777 | if (state->ws->focus_animation) |
| 778 | weston_view_animation_destroy(state->ws->focus_animation); |
| 779 | |
| 780 | state->ws->focus_animation = weston_fade_run( |
| 781 | state->ws->fsurf_front->view, |
| 782 | state->ws->fsurf_front->view->alpha, 0.0, 300, |
| 783 | focus_animation_done, state->ws); |
| 784 | } |
| 785 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 786 | wl_list_remove(&state->link); |
| 787 | focus_state_destroy(state); |
| 788 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 792 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 793 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 794 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 795 | |
| 796 | state = malloc(sizeof *state); |
| 797 | if (state == NULL) |
| 798 | return NULL; |
| 799 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 800 | state->keyboard_focus = NULL; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 801 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 802 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 803 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 804 | |
| 805 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 806 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 807 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 808 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 809 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 810 | |
| 811 | return state; |
| 812 | } |
| 813 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 814 | static struct focus_state * |
| 815 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 816 | { |
| 817 | struct workspace *ws = get_current_workspace(shell); |
| 818 | struct focus_state *state; |
| 819 | |
| 820 | wl_list_for_each(state, &ws->focus_list, link) |
| 821 | if (state->seat == seat) |
| 822 | break; |
| 823 | |
| 824 | if (&state->link == &ws->focus_list) |
| 825 | state = focus_state_create(seat, ws); |
| 826 | |
| 827 | return state; |
| 828 | } |
| 829 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 830 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 831 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 832 | { |
| 833 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 834 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 835 | |
| 836 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 837 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 838 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 839 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
| 843 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 844 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 845 | struct weston_seat *seat) |
| 846 | { |
| 847 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 848 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 849 | |
| 850 | wl_list_for_each(state, &ws->focus_list, link) { |
| 851 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 852 | surface = seat->keyboard->focus; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 853 | state->keyboard_focus = surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 854 | return; |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | static void |
| 860 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 861 | struct weston_surface *surface) |
| 862 | { |
| 863 | struct focus_state *state; |
| 864 | |
| 865 | wl_list_for_each(state, &ws->focus_list, link) |
| 866 | if (state->keyboard_focus == surface) |
| 867 | state->keyboard_focus = NULL; |
| 868 | } |
| 869 | |
| 870 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 871 | animate_focus_change(struct desktop_shell *shell, struct workspace *ws, |
| 872 | struct weston_view *from, struct weston_view *to) |
| 873 | { |
| 874 | struct weston_output *output; |
| 875 | bool focus_surface_created = false; |
| 876 | |
| 877 | /* FIXME: Only support dim animation using two layers */ |
| 878 | if (from == to || shell->focus_animation_type != ANIMATION_DIM_LAYER) |
| 879 | return; |
| 880 | |
| 881 | output = get_default_output(shell->compositor); |
| 882 | if (ws->fsurf_front == NULL && (from || to)) { |
| 883 | ws->fsurf_front = create_focus_surface(shell->compositor, output); |
| 884 | ws->fsurf_back = create_focus_surface(shell->compositor, output); |
| 885 | ws->fsurf_front->view->alpha = 0.0; |
| 886 | ws->fsurf_back->view->alpha = 0.0; |
| 887 | focus_surface_created = true; |
| 888 | } else { |
| 889 | wl_list_remove(&ws->fsurf_front->view->layer_link); |
| 890 | wl_list_remove(&ws->fsurf_back->view->layer_link); |
| 891 | } |
| 892 | |
| 893 | if (ws->focus_animation) { |
| 894 | weston_view_animation_destroy(ws->focus_animation); |
| 895 | ws->focus_animation = NULL; |
| 896 | } |
| 897 | |
| 898 | if (to) |
| 899 | wl_list_insert(&to->layer_link, |
| 900 | &ws->fsurf_front->view->layer_link); |
| 901 | else if (from) |
| 902 | wl_list_insert(&ws->layer.view_list, |
| 903 | &ws->fsurf_front->view->layer_link); |
| 904 | |
| 905 | if (focus_surface_created) { |
| 906 | ws->focus_animation = weston_fade_run( |
| 907 | ws->fsurf_front->view, |
| 908 | ws->fsurf_front->view->alpha, 0.6, 300, |
| 909 | focus_animation_done, ws); |
| 910 | } else if (from) { |
| 911 | wl_list_insert(&from->layer_link, |
| 912 | &ws->fsurf_back->view->layer_link); |
| 913 | ws->focus_animation = weston_stable_fade_run( |
| 914 | ws->fsurf_front->view, 0.0, |
| 915 | ws->fsurf_back->view, 0.6, |
| 916 | focus_animation_done, ws); |
| 917 | } else if (to) { |
| 918 | wl_list_insert(&ws->layer.view_list, |
| 919 | &ws->fsurf_back->view->layer_link); |
| 920 | ws->focus_animation = weston_stable_fade_run( |
| 921 | ws->fsurf_front->view, 0.0, |
| 922 | ws->fsurf_back->view, 0.6, |
| 923 | focus_animation_done, ws); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 928 | workspace_destroy(struct workspace *ws) |
| 929 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 930 | struct focus_state *state, *next; |
| 931 | |
| 932 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 933 | focus_state_destroy(state); |
| 934 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 935 | if (ws->fsurf_front) |
| 936 | focus_surface_destroy(ws->fsurf_front); |
| 937 | if (ws->fsurf_back) |
| 938 | focus_surface_destroy(ws->fsurf_back); |
| 939 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 940 | free(ws); |
| 941 | } |
| 942 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 943 | static void |
| 944 | seat_destroyed(struct wl_listener *listener, void *data) |
| 945 | { |
| 946 | struct weston_seat *seat = data; |
| 947 | struct focus_state *state, *next; |
| 948 | struct workspace *ws = container_of(listener, |
| 949 | struct workspace, |
| 950 | seat_destroyed_listener); |
| 951 | |
| 952 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 953 | if (state->seat == seat) |
| 954 | wl_list_remove(&state->link); |
| 955 | } |
| 956 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 957 | static struct workspace * |
| 958 | workspace_create(void) |
| 959 | { |
| 960 | struct workspace *ws = malloc(sizeof *ws); |
| 961 | if (ws == NULL) |
| 962 | return NULL; |
| 963 | |
| 964 | weston_layer_init(&ws->layer, NULL); |
| 965 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 966 | wl_list_init(&ws->focus_list); |
| 967 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 968 | ws->seat_destroyed_listener.notify = seat_destroyed; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 969 | ws->fsurf_front = NULL; |
| 970 | ws->fsurf_back = NULL; |
| 971 | ws->focus_animation = NULL; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 972 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 973 | return ws; |
| 974 | } |
| 975 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 976 | static int |
| 977 | workspace_is_empty(struct workspace *ws) |
| 978 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 979 | return wl_list_empty(&ws->layer.view_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 980 | } |
| 981 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 982 | static struct workspace * |
| 983 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 984 | { |
| 985 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 986 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 987 | pws += index; |
| 988 | return *pws; |
| 989 | } |
| 990 | |
| 991 | static struct workspace * |
| 992 | get_current_workspace(struct desktop_shell *shell) |
| 993 | { |
| 994 | return get_workspace(shell, shell->workspaces.current); |
| 995 | } |
| 996 | |
| 997 | static void |
| 998 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 999 | { |
| 1000 | struct workspace *ws; |
| 1001 | |
| 1002 | ws = get_workspace(shell, index); |
| 1003 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 1004 | |
| 1005 | shell->workspaces.current = index; |
| 1006 | } |
| 1007 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1008 | static unsigned int |
| 1009 | get_output_height(struct weston_output *output) |
| 1010 | { |
| 1011 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 1012 | } |
| 1013 | |
| 1014 | static void |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1015 | view_translate(struct workspace *ws, struct weston_view *view, double d) |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1016 | { |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1017 | struct weston_transform *transform; |
| 1018 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1019 | if (is_focus_view(view)) { |
| 1020 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1021 | transform = &fsurf->workspace_transform; |
| 1022 | } else { |
| 1023 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1024 | transform = &shsurf->workspace_transform; |
| 1025 | } |
| 1026 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1027 | if (wl_list_empty(&transform->link)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1028 | wl_list_insert(view->geometry.transformation_list.prev, |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1029 | &transform->link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1030 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1031 | weston_matrix_init(&transform->matrix); |
| 1032 | weston_matrix_translate(&transform->matrix, |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1033 | 0.0, d, 0.0); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1034 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | static void |
| 1038 | workspace_translate_out(struct workspace *ws, double fraction) |
| 1039 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1040 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1041 | unsigned int height; |
| 1042 | double d; |
| 1043 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1044 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1045 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1046 | d = height * fraction; |
| 1047 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1048 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | static void |
| 1053 | workspace_translate_in(struct workspace *ws, double fraction) |
| 1054 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1055 | struct weston_view *view; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1056 | unsigned int height; |
| 1057 | double d; |
| 1058 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1059 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
| 1060 | height = get_output_height(view->surface->output); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1061 | |
| 1062 | if (fraction > 0) |
| 1063 | d = -(height - height * fraction); |
| 1064 | else |
| 1065 | d = height + height * fraction; |
| 1066 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1067 | view_translate(ws, view, d); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1072 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 1073 | { |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1074 | struct wl_resource *resource; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1075 | |
Kristian Høgsberg | 2e3c396 | 2013-09-11 12:00:47 -0700 | [diff] [blame] | 1076 | wl_resource_for_each(resource, &shell->workspaces.client_list) |
| 1077 | workspace_manager_send_state(resource, |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1078 | shell->workspaces.current, |
| 1079 | shell->workspaces.num); |
| 1080 | } |
| 1081 | |
| 1082 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1083 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 1084 | unsigned int index, |
| 1085 | struct workspace *from, |
| 1086 | struct workspace *to) |
| 1087 | { |
| 1088 | shell->workspaces.current = index; |
| 1089 | |
| 1090 | shell->workspaces.anim_to = to; |
| 1091 | shell->workspaces.anim_from = from; |
| 1092 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 1093 | shell->workspaces.anim_timestamp = 0; |
| 1094 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1095 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | static void |
| 1099 | workspace_deactivate_transforms(struct workspace *ws) |
| 1100 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1101 | struct weston_view *view; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1102 | struct weston_transform *transform; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1103 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1104 | 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] | 1105 | if (is_focus_view(view)) { |
| 1106 | struct focus_surface *fsurf = get_focus_surface(view->surface); |
| 1107 | transform = &fsurf->workspace_transform; |
| 1108 | } else { |
| 1109 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 1110 | transform = &shsurf->workspace_transform; |
| 1111 | } |
| 1112 | |
| 1113 | if (!wl_list_empty(&transform->link)) { |
| 1114 | wl_list_remove(&transform->link); |
| 1115 | wl_list_init(&transform->link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1116 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1117 | weston_view_geometry_dirty(view); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | static void |
| 1122 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 1123 | struct workspace *from, |
| 1124 | struct workspace *to) |
| 1125 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1126 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1127 | |
| 1128 | wl_list_remove(&shell->workspaces.animation.link); |
| 1129 | workspace_deactivate_transforms(from); |
| 1130 | workspace_deactivate_transforms(to); |
| 1131 | shell->workspaces.anim_to = NULL; |
| 1132 | |
| 1133 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 1134 | } |
| 1135 | |
| 1136 | static void |
| 1137 | animate_workspace_change_frame(struct weston_animation *animation, |
| 1138 | struct weston_output *output, uint32_t msecs) |
| 1139 | { |
| 1140 | struct desktop_shell *shell = |
| 1141 | container_of(animation, struct desktop_shell, |
| 1142 | workspaces.animation); |
| 1143 | struct workspace *from = shell->workspaces.anim_from; |
| 1144 | struct workspace *to = shell->workspaces.anim_to; |
| 1145 | uint32_t t; |
| 1146 | double x, y; |
| 1147 | |
| 1148 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 1149 | finish_workspace_change_animation(shell, from, to); |
| 1150 | return; |
| 1151 | } |
| 1152 | |
| 1153 | if (shell->workspaces.anim_timestamp == 0) { |
| 1154 | if (shell->workspaces.anim_current == 0.0) |
| 1155 | shell->workspaces.anim_timestamp = msecs; |
| 1156 | else |
| 1157 | shell->workspaces.anim_timestamp = |
| 1158 | msecs - |
| 1159 | /* Invers of movement function 'y' below. */ |
| 1160 | (asin(1.0 - shell->workspaces.anim_current) * |
| 1161 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 1162 | M_2_PI); |
| 1163 | } |
| 1164 | |
| 1165 | t = msecs - shell->workspaces.anim_timestamp; |
| 1166 | |
| 1167 | /* |
| 1168 | * x = [0, π/2] |
| 1169 | * y(x) = sin(x) |
| 1170 | */ |
| 1171 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 1172 | y = sin(x); |
| 1173 | |
| 1174 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1175 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1176 | |
| 1177 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 1178 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 1179 | shell->workspaces.anim_current = y; |
| 1180 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1181 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1182 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1183 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1184 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | static void |
| 1188 | animate_workspace_change(struct desktop_shell *shell, |
| 1189 | unsigned int index, |
| 1190 | struct workspace *from, |
| 1191 | struct workspace *to) |
| 1192 | { |
| 1193 | struct weston_output *output; |
| 1194 | |
| 1195 | int dir; |
| 1196 | |
| 1197 | if (index > shell->workspaces.current) |
| 1198 | dir = -1; |
| 1199 | else |
| 1200 | dir = 1; |
| 1201 | |
| 1202 | shell->workspaces.current = index; |
| 1203 | |
| 1204 | shell->workspaces.anim_dir = dir; |
| 1205 | shell->workspaces.anim_from = from; |
| 1206 | shell->workspaces.anim_to = to; |
| 1207 | shell->workspaces.anim_current = 0.0; |
| 1208 | shell->workspaces.anim_timestamp = 0; |
| 1209 | |
| 1210 | output = container_of(shell->compositor->output_list.next, |
| 1211 | struct weston_output, link); |
| 1212 | wl_list_insert(&output->animation_list, |
| 1213 | &shell->workspaces.animation.link); |
| 1214 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1215 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1216 | |
| 1217 | workspace_translate_in(to, 0); |
| 1218 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 1219 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1220 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 1221 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1222 | } |
| 1223 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1224 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1225 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 1226 | struct workspace *from, struct workspace *to) |
| 1227 | { |
| 1228 | shell->workspaces.current = index; |
| 1229 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 1230 | wl_list_remove(&from->layer.link); |
| 1231 | } |
| 1232 | |
| 1233 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1234 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 1235 | { |
| 1236 | struct workspace *from; |
| 1237 | struct workspace *to; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1238 | struct focus_state *state; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1239 | |
| 1240 | if (index == shell->workspaces.current) |
| 1241 | return; |
| 1242 | |
| 1243 | /* Don't change workspace when there is any fullscreen surfaces. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1244 | if (!wl_list_empty(&shell->fullscreen_layer.view_list)) |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1245 | return; |
| 1246 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1247 | from = get_current_workspace(shell); |
| 1248 | to = get_workspace(shell, index); |
| 1249 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1250 | if (shell->workspaces.anim_from == to && |
| 1251 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1252 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1253 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1254 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1255 | return; |
| 1256 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1257 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1258 | if (shell->workspaces.anim_to != NULL) |
| 1259 | finish_workspace_change_animation(shell, |
| 1260 | shell->workspaces.anim_from, |
| 1261 | shell->workspaces.anim_to); |
| 1262 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1263 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 1264 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1265 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 1266 | wl_list_for_each(state, &from->focus_list, link) |
| 1267 | if (state->keyboard_focus) |
| 1268 | animate_focus_change(shell, from, |
| 1269 | get_default_view(state->keyboard_focus), NULL); |
| 1270 | |
| 1271 | wl_list_for_each(state, &to->focus_list, link) |
| 1272 | if (state->keyboard_focus) |
| 1273 | animate_focus_change(shell, to, |
| 1274 | NULL, get_default_view(state->keyboard_focus)); |
| 1275 | } |
| 1276 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1277 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 1278 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1279 | else |
| 1280 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1281 | |
| 1282 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1283 | } |
| 1284 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1285 | static bool |
| 1286 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 1287 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1288 | struct wl_list *list = &ws->layer.view_list; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1289 | struct wl_list *e; |
| 1290 | |
| 1291 | if (wl_list_empty(list)) |
| 1292 | return false; |
| 1293 | |
| 1294 | e = list->next; |
| 1295 | |
| 1296 | if (e->next != list) |
| 1297 | return false; |
| 1298 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1299 | return container_of(e, struct weston_view, layer_link)->surface == surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | static void |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1303 | move_surface_to_workspace(struct desktop_shell *shell, |
| 1304 | struct shell_surface *shsurf, |
| 1305 | uint32_t workspace) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1306 | { |
| 1307 | struct workspace *from; |
| 1308 | struct workspace *to; |
| 1309 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1310 | struct weston_surface *focus; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1311 | struct weston_view *view; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1312 | |
| 1313 | if (workspace == shell->workspaces.current) |
| 1314 | return; |
| 1315 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1316 | view = get_default_view(shsurf->surface); |
| 1317 | if (!view) |
| 1318 | return; |
| 1319 | |
| 1320 | assert(weston_surface_get_main_surface(view->surface) == view->surface); |
| 1321 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 1322 | if (workspace >= shell->workspaces.num) |
| 1323 | workspace = shell->workspaces.num - 1; |
| 1324 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1325 | from = get_current_workspace(shell); |
| 1326 | to = get_workspace(shell, workspace); |
| 1327 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1328 | wl_list_remove(&view->layer_link); |
| 1329 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1330 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1331 | shell_surface_update_child_surface_layers(shsurf); |
| 1332 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1333 | drop_focus_state(shell, from, view->surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1334 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 1335 | if (!seat->keyboard) |
| 1336 | continue; |
| 1337 | |
| 1338 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1339 | if (focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1340 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1341 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1342 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1343 | weston_view_damage_below(view); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1347 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1348 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1349 | unsigned int index) |
| 1350 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1351 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1352 | struct weston_view *view; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1353 | struct shell_surface *shsurf; |
| 1354 | struct workspace *from; |
| 1355 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1356 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1357 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1358 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1359 | view = get_default_view(surface); |
| 1360 | if (view == NULL || |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 1361 | index == shell->workspaces.current || |
| 1362 | is_focus_view(view)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1363 | return; |
| 1364 | |
| 1365 | from = get_current_workspace(shell); |
| 1366 | to = get_workspace(shell, index); |
| 1367 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1368 | wl_list_remove(&view->layer_link); |
| 1369 | wl_list_insert(&to->layer.view_list, &view->layer_link); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1370 | |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1371 | shsurf = get_shell_surface(surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 1372 | if (shsurf != NULL) |
| 1373 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1374 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1375 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1376 | drop_focus_state(shell, from, surface); |
| 1377 | |
| 1378 | if (shell->workspaces.anim_from == to && |
| 1379 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1380 | wl_list_remove(&to->layer.link); |
| 1381 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 1382 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1383 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1384 | broadcast_current_workspace_state(shell); |
| 1385 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1386 | return; |
| 1387 | } |
| 1388 | |
| 1389 | if (shell->workspaces.anim_to != NULL) |
| 1390 | finish_workspace_change_animation(shell, |
| 1391 | shell->workspaces.anim_from, |
| 1392 | shell->workspaces.anim_to); |
| 1393 | |
| 1394 | if (workspace_is_empty(from) && |
| 1395 | workspace_has_only(to, surface)) |
| 1396 | update_workspace(shell, index, from, to); |
| 1397 | else { |
Philip Withnall | 2c3849b | 2013-11-25 18:01:45 +0000 | [diff] [blame] | 1398 | if (shsurf != NULL && |
| 1399 | wl_list_empty(&shsurf->workspace_transform.link)) |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1400 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 1401 | &shsurf->workspace_transform.link); |
| 1402 | |
| 1403 | animate_workspace_change(shell, index, from, to); |
| 1404 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1405 | |
| 1406 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 1407 | |
| 1408 | state = ensure_focus_state(shell, seat); |
| 1409 | if (state != NULL) |
| 1410 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | static void |
| 1414 | workspace_manager_move_surface(struct wl_client *client, |
| 1415 | struct wl_resource *resource, |
| 1416 | struct wl_resource *surface_resource, |
| 1417 | uint32_t workspace) |
| 1418 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1419 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1420 | struct weston_surface *surface = |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1421 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1422 | struct weston_surface *main_surface; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1423 | struct shell_surface *shell_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1424 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 1425 | main_surface = weston_surface_get_main_surface(surface); |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1426 | shell_surface = get_shell_surface(main_surface); |
| 1427 | if (shell_surface == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1428 | return; |
Philip Withnall | 659163d | 2013-11-25 18:01:36 +0000 | [diff] [blame] | 1429 | |
| 1430 | move_surface_to_workspace(shell, shell_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1434 | workspace_manager_move_surface, |
| 1435 | }; |
| 1436 | |
| 1437 | static void |
| 1438 | unbind_resource(struct wl_resource *resource) |
| 1439 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1440 | wl_list_remove(wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | static void |
| 1444 | bind_workspace_manager(struct wl_client *client, |
| 1445 | void *data, uint32_t version, uint32_t id) |
| 1446 | { |
| 1447 | struct desktop_shell *shell = data; |
| 1448 | struct wl_resource *resource; |
| 1449 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1450 | resource = wl_resource_create(client, |
| 1451 | &workspace_manager_interface, 1, id); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1452 | |
| 1453 | if (resource == NULL) { |
| 1454 | weston_log("couldn't add workspace manager object"); |
| 1455 | return; |
| 1456 | } |
| 1457 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 1458 | wl_resource_set_implementation(resource, |
| 1459 | &workspace_manager_implementation, |
| 1460 | shell, unbind_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1461 | wl_list_insert(&shell->workspaces.client_list, |
| 1462 | wl_resource_get_link(resource)); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 1463 | |
| 1464 | workspace_manager_send_state(resource, |
| 1465 | shell->workspaces.current, |
| 1466 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1469 | static void |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1470 | touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time, |
| 1471 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1472 | { |
| 1473 | } |
| 1474 | |
| 1475 | static void |
| 1476 | touch_move_grab_up(struct weston_touch_grab *grab, uint32_t time, int touch_id) |
| 1477 | { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1478 | struct weston_touch_move_grab *move = |
| 1479 | (struct weston_touch_move_grab *) container_of( |
| 1480 | grab, struct shell_touch_grab, grab); |
Neil Roberts | e14aa4f | 2013-10-03 16:43:07 +0100 | [diff] [blame] | 1481 | |
Jonas Ådahl | 9484b69 | 2013-12-02 22:05:03 +0100 | [diff] [blame] | 1482 | if (grab->touch->num_tp == 0) { |
Jonas Ådahl | 1c6e63e | 2013-10-25 23:18:04 +0200 | [diff] [blame] | 1483 | shell_touch_grab_end(&move->base); |
| 1484 | free(move); |
| 1485 | } |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | static void |
| 1489 | touch_move_grab_motion(struct weston_touch_grab *grab, uint32_t time, |
| 1490 | int touch_id, wl_fixed_t sx, wl_fixed_t sy) |
| 1491 | { |
| 1492 | struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab; |
| 1493 | struct shell_surface *shsurf = move->base.shsurf; |
| 1494 | struct weston_surface *es; |
| 1495 | int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx); |
| 1496 | int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy); |
| 1497 | |
| 1498 | if (!shsurf) |
| 1499 | return; |
| 1500 | |
| 1501 | es = shsurf->surface; |
| 1502 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1503 | weston_view_set_position(shsurf->view, dx, dy); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1504 | |
| 1505 | weston_compositor_schedule_repaint(es->compositor); |
| 1506 | } |
| 1507 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1508 | static void |
| 1509 | touch_move_grab_cancel(struct weston_touch_grab *grab) |
| 1510 | { |
| 1511 | struct weston_touch_move_grab *move = |
| 1512 | (struct weston_touch_move_grab *) container_of( |
| 1513 | grab, struct shell_touch_grab, grab); |
| 1514 | |
| 1515 | shell_touch_grab_end(&move->base); |
| 1516 | free(move); |
| 1517 | } |
| 1518 | |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1519 | static const struct weston_touch_grab_interface touch_move_grab_interface = { |
| 1520 | touch_move_grab_down, |
| 1521 | touch_move_grab_up, |
| 1522 | touch_move_grab_motion, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1523 | touch_move_grab_cancel, |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1524 | }; |
| 1525 | |
| 1526 | static int |
| 1527 | surface_touch_move(struct shell_surface *shsurf, struct weston_seat *seat) |
| 1528 | { |
| 1529 | struct weston_touch_move_grab *move; |
| 1530 | |
| 1531 | if (!shsurf) |
| 1532 | return -1; |
| 1533 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1534 | if (shsurf->state.fullscreen) |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1535 | return 0; |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1536 | if (shsurf->grabbed) |
| 1537 | return 0; |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1538 | |
| 1539 | move = malloc(sizeof *move); |
| 1540 | if (!move) |
| 1541 | return -1; |
| 1542 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1543 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1544 | seat->touch->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1545 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1546 | seat->touch->grab_y; |
| 1547 | |
| 1548 | shell_touch_grab_start(&move->base, &touch_move_grab_interface, shsurf, |
| 1549 | seat->touch); |
| 1550 | |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
| 1554 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1555 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1556 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1560 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1561 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1562 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1563 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1564 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1565 | struct shell_surface *shsurf = move->base.shsurf; |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1566 | int dx, dy; |
| 1567 | |
| 1568 | weston_pointer_move(pointer, x, y); |
| 1569 | dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1570 | dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1571 | |
| 1572 | if (!shsurf) |
| 1573 | return; |
| 1574 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1575 | weston_view_set_position(shsurf->view, dx, dy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1576 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1577 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1581 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1582 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1583 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1584 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1585 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1586 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1587 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1588 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1589 | if (pointer->button_count == 0 && |
| 1590 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1591 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1592 | free(grab); |
| 1593 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1594 | } |
| 1595 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1596 | static void |
| 1597 | move_grab_cancel(struct weston_pointer_grab *grab) |
| 1598 | { |
| 1599 | struct shell_grab *shell_grab = |
| 1600 | container_of(grab, struct shell_grab, grab); |
| 1601 | |
| 1602 | shell_grab_end(shell_grab); |
| 1603 | free(grab); |
| 1604 | } |
| 1605 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1606 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1607 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1608 | move_grab_motion, |
| 1609 | move_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1610 | move_grab_cancel, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1611 | }; |
| 1612 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1613 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1614 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1615 | { |
| 1616 | struct weston_move_grab *move; |
| 1617 | |
| 1618 | if (!shsurf) |
| 1619 | return -1; |
| 1620 | |
Kristian Høgsberg | c85f1d4 | 2013-10-24 16:52:00 -0700 | [diff] [blame] | 1621 | if (shsurf->grabbed) |
| 1622 | return 0; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1623 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1624 | return 0; |
| 1625 | |
| 1626 | move = malloc(sizeof *move); |
| 1627 | if (!move) |
| 1628 | return -1; |
| 1629 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1630 | move->dx = wl_fixed_from_double(shsurf->view->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1631 | seat->pointer->grab_x; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1632 | move->dy = wl_fixed_from_double(shsurf->view->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1633 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1634 | |
| 1635 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1636 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1637 | |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
| 1641 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1642 | common_surface_move(struct wl_resource *resource, |
| 1643 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1644 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1645 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1646 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1647 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1648 | |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1649 | if (seat->pointer && |
| 1650 | seat->pointer->button_count > 0 && |
| 1651 | seat->pointer->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1652 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1653 | if ((surface == shsurf->surface) && |
| 1654 | (surface_move(shsurf, seat) < 0)) |
| 1655 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | e1b655d | 2013-08-28 23:16:20 -0700 | [diff] [blame] | 1656 | } else if (seat->touch && |
| 1657 | seat->touch->grab_serial == serial) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1658 | surface = weston_surface_get_main_surface(seat->touch->focus->surface); |
Rusty Lynch | 1084da5 | 2013-08-15 09:10:08 -0700 | [diff] [blame] | 1659 | if ((surface == shsurf->surface) && |
| 1660 | (surface_touch_move(shsurf, seat) < 0)) |
| 1661 | wl_resource_post_no_memory(resource); |
| 1662 | } |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1665 | static void |
| 1666 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1667 | struct wl_resource *seat_resource, uint32_t serial) |
| 1668 | { |
| 1669 | common_surface_move(resource, seat_resource, serial); |
| 1670 | } |
| 1671 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1672 | struct weston_resize_grab { |
| 1673 | struct shell_grab base; |
| 1674 | uint32_t edges; |
| 1675 | int32_t width, height; |
| 1676 | }; |
| 1677 | |
| 1678 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1679 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1680 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1681 | { |
| 1682 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1683 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1684 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1685 | int32_t width, height; |
| 1686 | wl_fixed_t from_x, from_y; |
| 1687 | wl_fixed_t to_x, to_y; |
| 1688 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1689 | weston_pointer_move(pointer, x, y); |
| 1690 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1691 | if (!shsurf) |
| 1692 | return; |
| 1693 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1694 | weston_view_from_global_fixed(shsurf->view, |
| 1695 | pointer->grab_x, pointer->grab_y, |
| 1696 | &from_x, &from_y); |
| 1697 | weston_view_from_global_fixed(shsurf->view, |
| 1698 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1699 | |
| 1700 | width = resize->width; |
| 1701 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1702 | width += wl_fixed_to_int(from_x - to_x); |
| 1703 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1704 | width += wl_fixed_to_int(to_x - from_x); |
| 1705 | } |
| 1706 | |
| 1707 | height = resize->height; |
| 1708 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1709 | height += wl_fixed_to_int(from_y - to_y); |
| 1710 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1711 | height += wl_fixed_to_int(to_y - from_y); |
| 1712 | } |
| 1713 | |
| 1714 | shsurf->client->send_configure(shsurf->surface, |
| 1715 | resize->edges, width, height); |
| 1716 | } |
| 1717 | |
| 1718 | static void |
| 1719 | send_configure(struct weston_surface *surface, |
| 1720 | uint32_t edges, int32_t width, int32_t height) |
| 1721 | { |
| 1722 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1723 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1724 | wl_shell_surface_send_configure(shsurf->resource, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1725 | edges, width, height); |
| 1726 | } |
| 1727 | |
| 1728 | static const struct weston_shell_client shell_client = { |
| 1729 | send_configure |
| 1730 | }; |
| 1731 | |
| 1732 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1733 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1734 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1735 | { |
| 1736 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1737 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1738 | enum wl_pointer_button_state state = state_w; |
| 1739 | |
| 1740 | if (pointer->button_count == 0 && |
| 1741 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1742 | shell_grab_end(&resize->base); |
| 1743 | free(grab); |
| 1744 | } |
| 1745 | } |
| 1746 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1747 | static void |
| 1748 | resize_grab_cancel(struct weston_pointer_grab *grab) |
| 1749 | { |
| 1750 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
| 1751 | |
| 1752 | shell_grab_end(&resize->base); |
| 1753 | free(grab); |
| 1754 | } |
| 1755 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1756 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1757 | noop_grab_focus, |
| 1758 | resize_grab_motion, |
| 1759 | resize_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1760 | resize_grab_cancel, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1761 | }; |
| 1762 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1763 | /* |
| 1764 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1765 | * in the surface coordinates system. */ |
| 1766 | static void |
| 1767 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1768 | int32_t *y, int32_t *w, int32_t *h) { |
| 1769 | pixman_region32_t region; |
| 1770 | pixman_box32_t *box; |
| 1771 | struct weston_subsurface *subsurface; |
| 1772 | |
| 1773 | pixman_region32_init_rect(®ion, 0, 0, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1774 | surface->width, |
| 1775 | surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1776 | |
| 1777 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1778 | pixman_region32_union_rect(®ion, ®ion, |
| 1779 | subsurface->position.x, |
| 1780 | subsurface->position.y, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1781 | subsurface->surface->width, |
| 1782 | subsurface->surface->height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | box = pixman_region32_extents(®ion); |
| 1786 | if (x) |
| 1787 | *x = box->x1; |
| 1788 | if (y) |
| 1789 | *y = box->y1; |
| 1790 | if (w) |
| 1791 | *w = box->x2 - box->x1; |
| 1792 | if (h) |
| 1793 | *h = box->y2 - box->y1; |
| 1794 | |
| 1795 | pixman_region32_fini(®ion); |
| 1796 | } |
| 1797 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1798 | static int |
| 1799 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1800 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1801 | { |
| 1802 | struct weston_resize_grab *resize; |
| 1803 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1804 | if (shsurf->state.fullscreen || shsurf->state.maximized) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1805 | return 0; |
| 1806 | |
| 1807 | if (edges == 0 || edges > 15 || |
| 1808 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1809 | return 0; |
| 1810 | |
| 1811 | resize = malloc(sizeof *resize); |
| 1812 | if (!resize) |
| 1813 | return -1; |
| 1814 | |
| 1815 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1816 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1817 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1818 | |
| 1819 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1820 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1821 | |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1826 | common_surface_resize(struct wl_resource *resource, |
| 1827 | struct wl_resource *seat_resource, uint32_t serial, |
| 1828 | uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1829 | { |
Jason Ekstrand | 44a3863 | 2013-06-14 10:08:00 -0500 | [diff] [blame] | 1830 | struct weston_seat *seat = wl_resource_get_user_data(seat_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1831 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1832 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1833 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 1834 | if (shsurf->state.fullscreen) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1835 | return; |
| 1836 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1837 | surface = weston_surface_get_main_surface(seat->pointer->focus->surface); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1838 | if (seat->pointer->button_count == 0 || |
| 1839 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1840 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1841 | return; |
| 1842 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1843 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1844 | wl_resource_post_no_memory(resource); |
| 1845 | } |
| 1846 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1847 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1848 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1849 | struct wl_resource *seat_resource, uint32_t serial, |
| 1850 | uint32_t edges) |
| 1851 | { |
| 1852 | common_surface_resize(resource, seat_resource, serial, edges); |
| 1853 | } |
| 1854 | |
| 1855 | static void |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1856 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer); |
| 1857 | |
| 1858 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1859 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1860 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1861 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1862 | struct weston_pointer *pointer = base->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1863 | struct weston_view *view; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1864 | wl_fixed_t sx, sy; |
| 1865 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1866 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 1867 | pointer->x, pointer->y, |
| 1868 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1869 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1870 | if (!grab->shsurf || grab->shsurf->surface != view->surface) |
Kristian Høgsberg | 6780073 | 2013-07-04 01:12:17 -0400 | [diff] [blame] | 1871 | end_busy_cursor(grab->shsurf, pointer); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1875 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 1876 | wl_fixed_t x, wl_fixed_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1877 | { |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 1878 | weston_pointer_move(grab->pointer, x, y); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1879 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1880 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1881 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1882 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1883 | uint32_t time, uint32_t button, uint32_t state) |
| 1884 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1885 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1886 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1887 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1888 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1889 | if (shsurf && button == BTN_LEFT && state) { |
| 1890 | activate(shsurf->shell, shsurf->surface, seat); |
| 1891 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1892 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1893 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1894 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1895 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1896 | } |
| 1897 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1898 | static void |
| 1899 | busy_cursor_grab_cancel(struct weston_pointer_grab *base) |
| 1900 | { |
| 1901 | struct shell_grab *grab = (struct shell_grab *) base; |
| 1902 | |
| 1903 | shell_grab_end(grab); |
| 1904 | free(grab); |
| 1905 | } |
| 1906 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1907 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1908 | busy_cursor_grab_focus, |
| 1909 | busy_cursor_grab_motion, |
| 1910 | busy_cursor_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 1911 | busy_cursor_grab_cancel, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1912 | }; |
| 1913 | |
| 1914 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1915 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1916 | { |
| 1917 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1918 | |
| 1919 | grab = malloc(sizeof *grab); |
| 1920 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1921 | return; |
| 1922 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1923 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1924 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1925 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1926 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1927 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1928 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1929 | { |
| 1930 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1931 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1932 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1933 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1934 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1935 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1936 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1937 | } |
| 1938 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1939 | static void |
| 1940 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1941 | { |
| 1942 | if (!shsurf || !shsurf->ping_timer) |
| 1943 | return; |
| 1944 | |
| 1945 | if (shsurf->ping_timer->source) |
| 1946 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1947 | |
| 1948 | free(shsurf->ping_timer); |
| 1949 | shsurf->ping_timer = NULL; |
| 1950 | } |
| 1951 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1952 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1953 | ping_timeout_handler(void *data) |
| 1954 | { |
| 1955 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1956 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1957 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1958 | /* Client is not responding */ |
| 1959 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1960 | |
| 1961 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Emilio Pozuelo Monfort | 3d0fc76 | 2013-11-22 16:21:20 +0100 | [diff] [blame] | 1962 | if (seat->pointer->focus && |
| 1963 | seat->pointer->focus->surface == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1964 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1965 | |
| 1966 | return 1; |
| 1967 | } |
| 1968 | |
| 1969 | static void |
| 1970 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1971 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1972 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1973 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1974 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1975 | |
| 1976 | if (!shsurf) |
| 1977 | return; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 1978 | if (!shsurf->resource) |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1979 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1980 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1981 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1982 | return; |
| 1983 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1984 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1985 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1986 | if (!shsurf->ping_timer) |
| 1987 | return; |
| 1988 | |
| 1989 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1990 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1991 | shsurf->ping_timer->source = |
| 1992 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1993 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1994 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 1995 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 1996 | wl_shell_surface_send_ping(shsurf->resource, serial); |
| 1997 | else if (shell_surface_is_xdg_surface(shsurf)) |
| 1998 | xdg_surface_send_ping(shsurf->resource, serial); |
| 1999 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2000 | xdg_popup_send_ping(shsurf->resource, serial); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2005 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 2006 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2007 | struct weston_pointer *pointer = data; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2008 | struct weston_view *view = pointer->focus; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2009 | struct weston_compositor *compositor; |
| 2010 | struct shell_surface *shsurf; |
| 2011 | uint32_t serial; |
| 2012 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2013 | if (!view) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2014 | return; |
| 2015 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2016 | compositor = view->surface->compositor; |
| 2017 | shsurf = get_shell_surface(view->surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2018 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 2019 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2020 | set_busy_cursor(shsurf, pointer); |
| 2021 | } else { |
| 2022 | serial = wl_display_next_serial(compositor->wl_display); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2023 | ping_handler(view->surface, serial); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 2028 | create_pointer_focus_listener(struct weston_seat *seat) |
| 2029 | { |
| 2030 | struct wl_listener *listener; |
| 2031 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2032 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 2033 | return; |
| 2034 | |
| 2035 | listener = malloc(sizeof *listener); |
| 2036 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2037 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2041 | xdg_surface_set_transient_for(struct wl_client *client, |
| 2042 | struct wl_resource *resource, |
| 2043 | struct wl_resource *parent_resource) |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2044 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2045 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2046 | struct weston_surface *parent = |
| 2047 | wl_resource_get_user_data(parent_resource); |
| 2048 | |
| 2049 | shell_surface_set_parent(shsurf, parent); |
| 2050 | } |
| 2051 | |
| 2052 | static void |
| 2053 | surface_pong(struct shell_surface *shsurf, uint32_t serial) |
| 2054 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2055 | struct weston_compositor *ec = shsurf->surface->compositor; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2056 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2057 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 2058 | if (shsurf->ping_timer == NULL) |
| 2059 | /* Just ignore unsolicited pong. */ |
| 2060 | return; |
| 2061 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2062 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2063 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 2064 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 2065 | if(seat->pointer) |
| 2066 | end_busy_cursor(shsurf, seat->pointer); |
| 2067 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2068 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2072 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2073 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 2074 | uint32_t serial) |
| 2075 | { |
| 2076 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2077 | |
| 2078 | surface_pong(shsurf, serial); |
| 2079 | |
| 2080 | } |
| 2081 | |
| 2082 | static void |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2083 | set_title(struct shell_surface *shsurf, const char *title) |
| 2084 | { |
| 2085 | free(shsurf->title); |
| 2086 | shsurf->title = strdup(title); |
| 2087 | } |
| 2088 | |
| 2089 | static void |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2090 | shell_surface_set_title(struct wl_client *client, |
| 2091 | struct wl_resource *resource, const char *title) |
| 2092 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2093 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2094 | |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 2095 | set_title(shsurf, title); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | static void |
| 2099 | shell_surface_set_class(struct wl_client *client, |
| 2100 | struct wl_resource *resource, const char *class) |
| 2101 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2102 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2103 | |
| 2104 | free(shsurf->class); |
| 2105 | shsurf->class = strdup(class); |
| 2106 | } |
| 2107 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2108 | static void |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2109 | restore_output_mode(struct weston_output *output) |
| 2110 | { |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2111 | if (output->current_mode != output->original_mode || |
| 2112 | (int32_t)output->current_scale != output->original_scale) |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2113 | weston_output_switch_mode(output, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2114 | output->original_mode, |
| 2115 | output->original_scale, |
| 2116 | WESTON_MODE_SWITCH_RESTORE_NATIVE); |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | static void |
| 2120 | restore_all_output_modes(struct weston_compositor *compositor) |
| 2121 | { |
| 2122 | struct weston_output *output; |
| 2123 | |
| 2124 | wl_list_for_each(output, &compositor->output_list, link) |
| 2125 | restore_output_mode(output); |
| 2126 | } |
| 2127 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2128 | static int |
| 2129 | get_output_panel_height(struct desktop_shell *shell, |
| 2130 | struct weston_output *output) |
| 2131 | { |
| 2132 | struct weston_view *view; |
| 2133 | int panel_height = 0; |
| 2134 | |
| 2135 | if (!output) |
| 2136 | return 0; |
| 2137 | |
| 2138 | wl_list_for_each(view, &shell->panel_layer.view_list, layer_link) { |
| 2139 | if (view->surface->output == output) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2140 | panel_height = view->surface->height; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | return panel_height; |
| 2146 | } |
| 2147 | |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2148 | /* The surface will be inserted into the list immediately after the link |
| 2149 | * returned by this function (i.e. will be stacked immediately above the |
| 2150 | * returned link). */ |
| 2151 | static struct wl_list * |
| 2152 | shell_surface_calculate_layer_link (struct shell_surface *shsurf) |
| 2153 | { |
| 2154 | struct workspace *ws; |
| 2155 | |
| 2156 | switch (shsurf->type) { |
Philip Withnall | da704d9 | 2013-11-25 18:01:46 +0000 | [diff] [blame] | 2157 | case SHELL_SURFACE_POPUP: { |
| 2158 | /* Popups should go at the front of the workspace of their |
| 2159 | * parent surface, rather than just in front of the parent. This |
| 2160 | * fixes the situation where there are two top-level windows: |
| 2161 | * - Above |
| 2162 | * - Below |
| 2163 | * and a pop-up menu is created for 'Below'. We want: |
| 2164 | * - Popup |
| 2165 | * - Above |
| 2166 | * - Below |
| 2167 | * not: |
| 2168 | * - Above |
| 2169 | * - Popup |
| 2170 | * - Below |
| 2171 | */ |
| 2172 | struct shell_surface *parent_shsurf; |
| 2173 | |
| 2174 | parent_shsurf = get_shell_surface(shsurf->parent); |
| 2175 | if (parent_shsurf != NULL) |
| 2176 | return shell_surface_calculate_layer_link(parent_shsurf); |
| 2177 | |
| 2178 | break; |
| 2179 | } |
| 2180 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2181 | case SHELL_SURFACE_TOPLEVEL: { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2182 | if (shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2183 | return &shsurf->shell->fullscreen_layer.view_list; |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2184 | } else if (shsurf->parent) { |
| 2185 | /* Move the surface to its parent layer so that |
| 2186 | * surfaces which are transient for fullscreen surfaces |
| 2187 | * don't get hidden by the fullscreen surfaces. |
| 2188 | * However, unlike popups, transient surfaces are |
| 2189 | * stacked in front of their parent but not in front of |
| 2190 | * other surfaces of the same type. */ |
| 2191 | struct weston_view *parent; |
| 2192 | |
| 2193 | /* TODO: Handle a parent with multiple views */ |
| 2194 | parent = get_default_view(shsurf->parent); |
| 2195 | if (parent) |
| 2196 | return parent->layer_link.prev; |
| 2197 | } |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2198 | break; |
| 2199 | } |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2200 | |
| 2201 | case SHELL_SURFACE_XWAYLAND: |
Philip Withnall | 07926d9 | 2013-11-25 18:01:40 +0000 | [diff] [blame] | 2202 | case SHELL_SURFACE_NONE: |
| 2203 | default: |
| 2204 | /* Go to the fallback, below. */ |
| 2205 | break; |
| 2206 | } |
| 2207 | |
| 2208 | /* Move the surface to a normal workspace layer so that surfaces |
| 2209 | * which were previously fullscreen or transient are no longer |
| 2210 | * rendered on top. */ |
| 2211 | ws = get_current_workspace(shsurf->shell); |
| 2212 | return &ws->layer.view_list; |
| 2213 | } |
| 2214 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2215 | static void |
| 2216 | shell_surface_update_child_surface_layers (struct shell_surface *shsurf) |
| 2217 | { |
| 2218 | struct shell_surface *child; |
| 2219 | |
| 2220 | /* Move the child layers to the same workspace as shsurf. They will be |
| 2221 | * stacked above shsurf. */ |
| 2222 | wl_list_for_each_reverse(child, &shsurf->children_list, children_link) { |
| 2223 | if (shsurf->view->layer_link.prev != &child->view->layer_link) { |
| 2224 | weston_view_geometry_dirty(child->view); |
| 2225 | wl_list_remove(&child->view->layer_link); |
| 2226 | wl_list_insert(shsurf->view->layer_link.prev, |
| 2227 | &child->view->layer_link); |
| 2228 | weston_view_geometry_dirty(child->view); |
| 2229 | weston_surface_damage(child->surface); |
| 2230 | |
| 2231 | /* Recurse. We don’t expect this to recurse very far (if |
| 2232 | * at all) because that would imply we have transient |
| 2233 | * (or popup) children of transient surfaces, which |
| 2234 | * would be unusual. */ |
| 2235 | shell_surface_update_child_surface_layers(child); |
| 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2240 | /* 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] | 2241 | * geometry to ensure the changes are redrawn. |
| 2242 | * |
| 2243 | * If any child surfaces exist and are mapped, ensure they’re in the same layer |
| 2244 | * as this surface. */ |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2245 | static void |
| 2246 | shell_surface_update_layer(struct shell_surface *shsurf) |
| 2247 | { |
| 2248 | struct wl_list *new_layer_link; |
| 2249 | |
| 2250 | new_layer_link = shell_surface_calculate_layer_link(shsurf); |
| 2251 | |
| 2252 | if (new_layer_link == &shsurf->view->layer_link) |
| 2253 | return; |
| 2254 | |
| 2255 | weston_view_geometry_dirty(shsurf->view); |
| 2256 | wl_list_remove(&shsurf->view->layer_link); |
| 2257 | wl_list_insert(new_layer_link, &shsurf->view->layer_link); |
| 2258 | weston_view_geometry_dirty(shsurf->view); |
| 2259 | weston_surface_damage(shsurf->surface); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2260 | |
| 2261 | shell_surface_update_child_surface_layers(shsurf); |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2264 | static void |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2265 | shell_surface_set_parent(struct shell_surface *shsurf, |
| 2266 | struct weston_surface *parent) |
| 2267 | { |
| 2268 | shsurf->parent = parent; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2269 | |
| 2270 | wl_list_remove(&shsurf->children_link); |
| 2271 | wl_list_init(&shsurf->children_link); |
| 2272 | |
| 2273 | /* Insert into the parent surface’s child list. */ |
| 2274 | if (parent != NULL) { |
| 2275 | struct shell_surface *parent_shsurf = get_shell_surface(parent); |
| 2276 | if (parent_shsurf != NULL) |
| 2277 | wl_list_insert(&parent_shsurf->children_list, |
| 2278 | &shsurf->children_link); |
| 2279 | } |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
| 2282 | static void |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2283 | shell_surface_set_output(struct shell_surface *shsurf, |
| 2284 | struct weston_output *output) |
| 2285 | { |
| 2286 | struct weston_surface *es = shsurf->surface; |
| 2287 | |
| 2288 | /* get the default output, if the client set it as NULL |
| 2289 | check whether the ouput is available */ |
| 2290 | if (output) |
| 2291 | shsurf->output = output; |
| 2292 | else if (es->output) |
| 2293 | shsurf->output = es->output; |
| 2294 | else |
| 2295 | shsurf->output = get_default_output(es->compositor); |
| 2296 | } |
| 2297 | |
| 2298 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2299 | surface_clear_next_states(struct shell_surface *shsurf) |
| 2300 | { |
| 2301 | shsurf->next_state.maximized = false; |
| 2302 | shsurf->next_state.fullscreen = false; |
| 2303 | |
| 2304 | if ((shsurf->next_state.maximized != shsurf->state.maximized) || |
| 2305 | (shsurf->next_state.fullscreen != shsurf->state.fullscreen)) |
| 2306 | shsurf->state_changed = true; |
| 2307 | } |
| 2308 | |
| 2309 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2310 | set_toplevel(struct shell_surface *shsurf) |
| 2311 | { |
| 2312 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2313 | |
| 2314 | /* The layer_link is updated in set_surface_type(), |
| 2315 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | static void |
| 2319 | shell_surface_set_toplevel(struct wl_client *client, |
| 2320 | struct wl_resource *resource) |
| 2321 | { |
| 2322 | struct shell_surface *surface = wl_resource_get_user_data(resource); |
| 2323 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2324 | shell_surface_set_parent(surface, NULL); |
| 2325 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2326 | surface_clear_next_states(surface); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2327 | set_toplevel(surface); |
| 2328 | } |
| 2329 | |
| 2330 | static void |
| 2331 | set_transient(struct shell_surface *shsurf, |
| 2332 | struct weston_surface *parent, int x, int y, uint32_t flags) |
| 2333 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2334 | assert(parent != NULL); |
| 2335 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2336 | shsurf->transient.x = x; |
| 2337 | shsurf->transient.y = y; |
| 2338 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2339 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2340 | shsurf->next_state.relative = true; |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2341 | |
| 2342 | /* The layer_link is updated in set_surface_type(), |
| 2343 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | static void |
| 2347 | shell_surface_set_transient(struct wl_client *client, |
| 2348 | struct wl_resource *resource, |
| 2349 | struct wl_resource *parent_resource, |
| 2350 | int x, int y, uint32_t flags) |
| 2351 | { |
| 2352 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2353 | struct weston_surface *parent = |
| 2354 | wl_resource_get_user_data(parent_resource); |
| 2355 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2356 | shell_surface_set_parent(shsurf, parent); |
| 2357 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2358 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2359 | set_transient(shsurf, parent, x, y, flags); |
| 2360 | } |
| 2361 | |
| 2362 | static void |
| 2363 | set_fullscreen(struct shell_surface *shsurf, |
| 2364 | uint32_t method, |
| 2365 | uint32_t framerate, |
| 2366 | struct weston_output *output) |
| 2367 | { |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2368 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2369 | |
| 2370 | shsurf->fullscreen_output = shsurf->output; |
| 2371 | shsurf->fullscreen.type = method; |
| 2372 | shsurf->fullscreen.framerate = framerate; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2373 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2374 | shsurf->next_type = shsurf->type; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2375 | |
| 2376 | shsurf->client->send_configure(shsurf->surface, 0, |
| 2377 | shsurf->output->width, |
| 2378 | shsurf->output->height); |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 2379 | |
| 2380 | /* The layer_link is updated in set_surface_type(), |
| 2381 | * called from configure. */ |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | static void |
| 2385 | unset_fullscreen(struct shell_surface *shsurf) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2386 | { |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2387 | /* Unset the fullscreen output, driver configuration and transforms. */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2388 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2389 | shell_surface_is_top_fullscreen(shsurf)) { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2390 | restore_output_mode(shsurf->fullscreen_output); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2391 | } |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2392 | shsurf->fullscreen_output = NULL; |
| 2393 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2394 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2395 | shsurf->fullscreen.framerate = 0; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2396 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2397 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 2398 | wl_list_init(&shsurf->fullscreen.transform.link); |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2399 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2400 | if (shsurf->fullscreen.black_view) |
| 2401 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
| 2402 | shsurf->fullscreen.black_view = NULL; |
Philip Withnall | f85fe84 | 2013-11-25 18:01:37 +0000 | [diff] [blame] | 2403 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2404 | weston_view_set_position(shsurf->view, |
| 2405 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2406 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2407 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2408 | &shsurf->rotation.transform.link); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2409 | shsurf->saved_rotation_valid = false; |
| 2410 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 2411 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2412 | /* Layer is updated in set_surface_type(). */ |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2413 | } |
| 2414 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2415 | static void |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2416 | shell_surface_set_fullscreen(struct wl_client *client, |
| 2417 | struct wl_resource *resource, |
| 2418 | uint32_t method, |
| 2419 | uint32_t framerate, |
| 2420 | struct wl_resource *output_resource) |
| 2421 | { |
| 2422 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2423 | struct weston_output *output; |
| 2424 | |
| 2425 | if (output_resource) |
| 2426 | output = wl_resource_get_user_data(output_resource); |
| 2427 | else |
| 2428 | output = NULL; |
| 2429 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2430 | shell_surface_set_parent(shsurf, NULL); |
| 2431 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2432 | surface_clear_next_states(shsurf); |
| 2433 | shsurf->next_state.fullscreen = true; |
| 2434 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2435 | set_fullscreen(shsurf, method, framerate, output); |
| 2436 | } |
| 2437 | |
| 2438 | static void |
| 2439 | set_popup(struct shell_surface *shsurf, |
| 2440 | struct weston_surface *parent, |
| 2441 | struct weston_seat *seat, |
| 2442 | uint32_t serial, |
| 2443 | int32_t x, |
| 2444 | int32_t y) |
| 2445 | { |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2446 | assert(parent != NULL); |
| 2447 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2448 | shsurf->popup.shseat = get_shell_seat(seat); |
| 2449 | shsurf->popup.serial = serial; |
| 2450 | shsurf->popup.x = x; |
| 2451 | shsurf->popup.y = y; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2452 | |
Philip Withnall | b995e1d | 2013-11-25 18:01:39 +0000 | [diff] [blame] | 2453 | shsurf->next_type = SHELL_SURFACE_POPUP; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | static void |
| 2457 | shell_surface_set_popup(struct wl_client *client, |
| 2458 | struct wl_resource *resource, |
| 2459 | struct wl_resource *seat_resource, |
| 2460 | uint32_t serial, |
| 2461 | struct wl_resource *parent_resource, |
| 2462 | int32_t x, int32_t y, uint32_t flags) |
| 2463 | { |
| 2464 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2465 | struct weston_surface *parent = |
| 2466 | wl_resource_get_user_data(parent_resource); |
| 2467 | |
| 2468 | shell_surface_set_parent(shsurf, parent); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2469 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2470 | surface_clear_next_states(shsurf); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2471 | set_popup(shsurf, |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2472 | parent, |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2473 | wl_resource_get_user_data(seat_resource), |
| 2474 | serial, x, y); |
| 2475 | } |
| 2476 | |
| 2477 | static void |
| 2478 | set_maximized(struct shell_surface *shsurf, |
| 2479 | struct weston_output *output) |
| 2480 | { |
| 2481 | struct desktop_shell *shell; |
| 2482 | uint32_t edges = 0, panel_height = 0; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2483 | |
Philip Withnall | 352e7ed | 2013-11-25 18:01:35 +0000 | [diff] [blame] | 2484 | shell_surface_set_output(shsurf, output); |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2485 | |
| 2486 | shell = shell_surface_get_shell(shsurf); |
| 2487 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 2488 | edges = WL_SHELL_SURFACE_RESIZE_TOP | WL_SHELL_SURFACE_RESIZE_LEFT; |
| 2489 | |
| 2490 | shsurf->client->send_configure(shsurf->surface, edges, |
| 2491 | shsurf->output->width, |
| 2492 | shsurf->output->height - panel_height); |
| 2493 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2494 | shsurf->next_type = shsurf->type; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | static void |
| 2498 | unset_maximized(struct shell_surface *shsurf) |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2499 | { |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2500 | /* undo all maximized things here */ |
| 2501 | shsurf->output = get_default_output(shsurf->surface->compositor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2502 | weston_view_set_position(shsurf->view, |
| 2503 | shsurf->saved_x, |
| 2504 | shsurf->saved_y); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2505 | |
| 2506 | if (shsurf->saved_rotation_valid) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2507 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
| 2508 | &shsurf->rotation.transform.link); |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2509 | shsurf->saved_rotation_valid = false; |
| 2510 | } |
| 2511 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2512 | /* Layer is updated in set_surface_type(). */ |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 2513 | } |
| 2514 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2515 | static void |
| 2516 | shell_surface_set_maximized(struct wl_client *client, |
| 2517 | struct wl_resource *resource, |
| 2518 | struct wl_resource *output_resource) |
| 2519 | { |
| 2520 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 2521 | struct weston_output *output; |
| 2522 | |
| 2523 | if (output_resource) |
| 2524 | output = wl_resource_get_user_data(output_resource); |
| 2525 | else |
| 2526 | output = NULL; |
| 2527 | |
Rafael Antognolli | 4b99a40 | 2013-12-03 15:35:44 -0200 | [diff] [blame] | 2528 | shell_surface_set_parent(shsurf, NULL); |
| 2529 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2530 | surface_clear_next_states(shsurf); |
| 2531 | shsurf->next_state.maximized = true; |
| 2532 | shsurf->state_changed = true; |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2533 | set_maximized(shsurf, output); |
| 2534 | } |
| 2535 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2536 | /* This is only ever called from set_surface_type(), so there’s no need to |
| 2537 | * update layer_links here, since they’ll be updated when we return. */ |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2538 | static int |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2539 | reset_surface_type(struct shell_surface *surface) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2540 | { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2541 | if (surface->state.fullscreen) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2542 | unset_fullscreen(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2543 | if (surface->state.maximized) |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2544 | unset_maximized(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2545 | |
| 2546 | surface->type = SHELL_SURFACE_NONE; |
| 2547 | return 0; |
| 2548 | } |
| 2549 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2550 | static void |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2551 | set_full_output(struct shell_surface *shsurf) |
| 2552 | { |
| 2553 | shsurf->saved_x = shsurf->view->geometry.x; |
| 2554 | shsurf->saved_y = shsurf->view->geometry.y; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 2555 | shsurf->saved_width = shsurf->surface->width; |
| 2556 | shsurf->saved_height = shsurf->surface->height; |
| 2557 | shsurf->saved_size_valid = true; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2558 | shsurf->saved_position_valid = true; |
| 2559 | |
| 2560 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 2561 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2562 | wl_list_init(&shsurf->rotation.transform.link); |
| 2563 | weston_view_geometry_dirty(shsurf->view); |
| 2564 | shsurf->saved_rotation_valid = true; |
| 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2569 | set_surface_type(struct shell_surface *shsurf) |
| 2570 | { |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2571 | struct weston_surface *pes = shsurf->parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2572 | struct weston_view *pev = get_default_view(pes); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2573 | |
Philip Withnall | becb77e | 2013-11-25 18:01:30 +0000 | [diff] [blame] | 2574 | reset_surface_type(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2575 | |
| 2576 | shsurf->type = shsurf->next_type; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2577 | shsurf->state = shsurf->next_state; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2578 | shsurf->next_type = SHELL_SURFACE_NONE; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2579 | shsurf->state_changed = false; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2580 | |
| 2581 | switch (shsurf->type) { |
| 2582 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2583 | if (shsurf->state.maximized || shsurf->state.fullscreen) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2584 | set_full_output(shsurf); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2585 | } else if (shsurf->state.relative && pev) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2586 | weston_view_set_position(shsurf->view, |
| 2587 | pev->geometry.x + shsurf->transient.x, |
| 2588 | pev->geometry.y + shsurf->transient.y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 2589 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2590 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2591 | case SHELL_SURFACE_XWAYLAND: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2592 | weston_view_set_position(shsurf->view, shsurf->transient.x, |
| 2593 | shsurf->transient.y); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2594 | break; |
| 2595 | |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 2596 | case SHELL_SURFACE_POPUP: |
| 2597 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2598 | default: |
| 2599 | break; |
| 2600 | } |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 2601 | |
| 2602 | /* Update the surface’s layer. */ |
| 2603 | shell_surface_update_layer(shsurf); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2604 | } |
| 2605 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2606 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2607 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2608 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2609 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2610 | } |
| 2611 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2612 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2613 | 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] | 2614 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2615 | static struct weston_view * |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2616 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2617 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2618 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2619 | { |
| 2620 | struct weston_surface *surface = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2621 | struct weston_view *view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2622 | |
| 2623 | surface = weston_surface_create(ec); |
| 2624 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2625 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2626 | return NULL; |
| 2627 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2628 | view = weston_view_create(surface); |
| 2629 | if (surface == NULL) { |
| 2630 | weston_log("no memory\n"); |
| 2631 | weston_surface_destroy(surface); |
| 2632 | return NULL; |
| 2633 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2634 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2635 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2636 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2637 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 2638 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 2639 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 2640 | pixman_region32_fini(&surface->input); |
| 2641 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2642 | |
Xiong Zhang | becf5a3 | 2013-11-29 11:18:14 +0800 | [diff] [blame] | 2643 | surface->width = w; |
| 2644 | surface->height = h; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2645 | weston_view_set_position(view, x, y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2646 | |
| 2647 | return view; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2648 | } |
| 2649 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2650 | static void |
| 2651 | shell_ensure_fullscreen_black_view(struct shell_surface *shsurf) |
| 2652 | { |
| 2653 | struct weston_output *output = shsurf->fullscreen_output; |
| 2654 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2655 | assert(shsurf->state.fullscreen); |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2656 | |
| 2657 | if (!shsurf->fullscreen.black_view) |
| 2658 | shsurf->fullscreen.black_view = |
| 2659 | create_black_surface(shsurf->surface->compositor, |
| 2660 | shsurf->surface, |
| 2661 | output->x, output->y, |
| 2662 | output->width, |
| 2663 | output->height); |
| 2664 | |
| 2665 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2666 | wl_list_remove(&shsurf->fullscreen.black_view->layer_link); |
| 2667 | wl_list_insert(&shsurf->view->layer_link, |
| 2668 | &shsurf->fullscreen.black_view->layer_link); |
| 2669 | weston_view_geometry_dirty(shsurf->fullscreen.black_view); |
| 2670 | weston_surface_damage(shsurf->surface); |
| 2671 | } |
| 2672 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2673 | /* Create black surface and append it to the associated fullscreen surface. |
| 2674 | * Handle size dismatch and positioning according to the method. */ |
| 2675 | static void |
| 2676 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 2677 | { |
| 2678 | struct weston_output *output = shsurf->fullscreen_output; |
| 2679 | struct weston_surface *surface = shsurf->surface; |
| 2680 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2681 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2682 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2683 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2684 | if (shsurf->fullscreen.type != WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER) |
| 2685 | restore_output_mode(output); |
| 2686 | |
Philip Withnall | ed8f1a9 | 2013-11-25 18:01:43 +0000 | [diff] [blame] | 2687 | shell_ensure_fullscreen_black_view(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2688 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2689 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2690 | &surf_width, &surf_height); |
| 2691 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2692 | switch (shsurf->fullscreen.type) { |
| 2693 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2694 | if (surface->buffer_ref.buffer) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2695 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2696 | break; |
| 2697 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2698 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2699 | if (output->width == surf_width && |
| 2700 | output->height == surf_height) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2701 | weston_view_set_position(shsurf->view, |
| 2702 | output->x - surf_x, |
| 2703 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 2704 | break; |
| 2705 | } |
| 2706 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2707 | matrix = &shsurf->fullscreen.transform.matrix; |
| 2708 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2709 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2710 | output_aspect = (float) output->width / |
| 2711 | (float) output->height; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2712 | /* XXX: Use surf_width and surf_height here? */ |
| 2713 | surface_aspect = (float) surface->width / |
| 2714 | (float) surface->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2715 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2716 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2717 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2718 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2719 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2720 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2721 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2722 | weston_matrix_scale(matrix, scale, scale, 1); |
| 2723 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2724 | wl_list_insert(&shsurf->view->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2725 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 2726 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 2727 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2728 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 2729 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2730 | break; |
| 2731 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2732 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2733 | struct weston_mode mode = {0, |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2734 | surf_width * surface->buffer_viewport.scale, |
| 2735 | surf_height * surface->buffer_viewport.scale, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2736 | shsurf->fullscreen.framerate}; |
| 2737 | |
Pekka Paalanen | 1fd9c0f | 2013-11-26 18:19:41 +0100 | [diff] [blame] | 2738 | if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale, |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2739 | WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2740 | weston_view_set_position(shsurf->view, |
| 2741 | output->x - surf_x, |
| 2742 | output->y - surf_y); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2743 | shsurf->fullscreen.black_view->surface->width = output->width; |
| 2744 | shsurf->fullscreen.black_view->surface->height = output->height; |
| 2745 | weston_view_set_position(shsurf->fullscreen.black_view, |
| 2746 | output->x - surf_x, |
| 2747 | output->y - surf_y); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2748 | break; |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2749 | } else { |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 2750 | restore_output_mode(output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2751 | center_on_output(shsurf->view, output); |
Alexander Larsson | d622ed3 | 2013-05-28 16:23:40 +0200 | [diff] [blame] | 2752 | } |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2753 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2754 | break; |
| 2755 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2756 | center_on_output(shsurf->view, output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2757 | break; |
| 2758 | default: |
| 2759 | break; |
| 2760 | } |
| 2761 | } |
| 2762 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2763 | static void |
| 2764 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 2765 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2766 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2767 | } |
| 2768 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2769 | static void |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2770 | set_xwayland(struct shell_surface *shsurf, int x, int y, uint32_t flags) |
| 2771 | { |
| 2772 | /* XXX: using the same fields for transient type */ |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 2773 | surface_clear_next_states(shsurf); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2774 | shsurf->transient.x = x; |
| 2775 | shsurf->transient.y = y; |
| 2776 | shsurf->transient.flags = flags; |
Philip Withnall | dc4332f | 2013-11-25 18:01:38 +0000 | [diff] [blame] | 2777 | |
| 2778 | shell_surface_set_parent(shsurf, NULL); |
| 2779 | |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2780 | shsurf->next_type = SHELL_SURFACE_XWAYLAND; |
| 2781 | } |
| 2782 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2783 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2784 | |
| 2785 | static void |
| 2786 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 2787 | { |
| 2788 | struct shell_seat *shseat = |
| 2789 | container_of(listener, |
| 2790 | struct shell_seat, seat_destroy_listener); |
| 2791 | struct shell_surface *shsurf, *prev = NULL; |
| 2792 | |
| 2793 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2794 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2795 | shseat->popup_grab.client = NULL; |
| 2796 | |
| 2797 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2798 | shsurf->popup.shseat = NULL; |
| 2799 | if (prev) { |
| 2800 | wl_list_init(&prev->popup.grab_link); |
| 2801 | } |
| 2802 | prev = shsurf; |
| 2803 | } |
| 2804 | wl_list_init(&prev->popup.grab_link); |
| 2805 | } |
| 2806 | |
| 2807 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 2808 | free(shseat); |
| 2809 | } |
| 2810 | |
| 2811 | static struct shell_seat * |
| 2812 | create_shell_seat(struct weston_seat *seat) |
| 2813 | { |
| 2814 | struct shell_seat *shseat; |
| 2815 | |
| 2816 | shseat = calloc(1, sizeof *shseat); |
| 2817 | if (!shseat) { |
| 2818 | weston_log("no memory to allocate shell seat\n"); |
| 2819 | return NULL; |
| 2820 | } |
| 2821 | |
| 2822 | shseat->seat = seat; |
| 2823 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2824 | |
| 2825 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 2826 | wl_signal_add(&seat->destroy_signal, |
| 2827 | &shseat->seat_destroy_listener); |
| 2828 | |
| 2829 | return shseat; |
| 2830 | } |
| 2831 | |
| 2832 | static struct shell_seat * |
| 2833 | get_shell_seat(struct weston_seat *seat) |
| 2834 | { |
| 2835 | struct wl_listener *listener; |
| 2836 | |
| 2837 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 2838 | if (listener == NULL) |
| 2839 | return create_shell_seat(seat); |
| 2840 | |
| 2841 | return container_of(listener, |
| 2842 | struct shell_seat, seat_destroy_listener); |
| 2843 | } |
| 2844 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 2845 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2846 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2847 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2848 | struct weston_pointer *pointer = grab->pointer; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2849 | struct weston_view *view; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2850 | struct shell_seat *shseat = |
| 2851 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2852 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 2853 | wl_fixed_t sx, sy; |
| 2854 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2855 | view = weston_compositor_pick_view(pointer->seat->compositor, |
| 2856 | pointer->x, pointer->y, |
| 2857 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2858 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2859 | if (view && view->surface->resource && |
| 2860 | wl_resource_get_client(view->surface->resource) == client) { |
| 2861 | weston_pointer_set_focus(pointer, view, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2862 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2863 | weston_pointer_set_focus(pointer, NULL, |
| 2864 | wl_fixed_from_int(0), |
| 2865 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2870 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 2871 | wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2872 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2873 | struct weston_pointer *pointer = grab->pointer; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2874 | struct wl_resource *resource; |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2875 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2876 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 2877 | weston_pointer_move(pointer, x, y); |
| 2878 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2879 | wl_resource_for_each(resource, &pointer->focus_resource_list) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2880 | weston_view_from_global_fixed(pointer->focus, |
| 2881 | pointer->x, pointer->y, |
| 2882 | &sx, &sy); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2883 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2884 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2888 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2889 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2890 | { |
| 2891 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2892 | struct shell_seat *shseat = |
| 2893 | container_of(grab, struct shell_seat, popup_grab.grab); |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 2894 | struct wl_display *display = shseat->seat->compositor->wl_display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2895 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2896 | uint32_t serial; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2897 | struct wl_list *resource_list; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2898 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2899 | resource_list = &grab->pointer->focus_resource_list; |
| 2900 | if (!wl_list_empty(resource_list)) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2901 | serial = wl_display_get_serial(display); |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 2902 | wl_resource_for_each(resource, resource_list) { |
| 2903 | wl_pointer_send_button(resource, serial, |
| 2904 | time, button, state); |
| 2905 | } |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2906 | } else 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 || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2908 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2909 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2910 | } |
| 2911 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2912 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2913 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2914 | } |
| 2915 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2916 | static void |
| 2917 | popup_grab_cancel(struct weston_pointer_grab *grab) |
| 2918 | { |
| 2919 | popup_grab_end(grab->pointer); |
| 2920 | } |
| 2921 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2922 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2923 | popup_grab_focus, |
| 2924 | popup_grab_motion, |
| 2925 | popup_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 2926 | popup_grab_cancel, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2927 | }; |
| 2928 | |
| 2929 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 2930 | shell_surface_send_popup_done(struct shell_surface *shsurf) |
| 2931 | { |
| 2932 | if (shell_surface_is_wl_shell_surface(shsurf)) |
| 2933 | wl_shell_surface_send_popup_done(shsurf->resource); |
| 2934 | else if (shell_surface_is_xdg_popup(shsurf)) |
| 2935 | xdg_popup_send_popup_done(shsurf->resource, |
| 2936 | shsurf->popup.serial); |
| 2937 | } |
| 2938 | |
| 2939 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2940 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2941 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2942 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2943 | struct shell_seat *shseat = |
| 2944 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2945 | struct shell_surface *shsurf; |
| 2946 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2947 | |
| 2948 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2949 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2950 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2951 | shseat->popup_grab.grab.interface = NULL; |
| 2952 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2953 | /* Send the popup_done event to all the popups open */ |
| 2954 | 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] | 2955 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2956 | shsurf->popup.shseat = NULL; |
| 2957 | if (prev) { |
| 2958 | wl_list_init(&prev->popup.grab_link); |
| 2959 | } |
| 2960 | prev = shsurf; |
| 2961 | } |
| 2962 | wl_list_init(&prev->popup.grab_link); |
| 2963 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | static void |
| 2968 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2969 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2970 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2971 | |
| 2972 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 2973 | shseat->popup_grab.client = wl_resource_get_client(shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2974 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2975 | /* We must make sure here that this popup was opened after |
| 2976 | * a mouse press, and not just by moving around with other |
| 2977 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2978 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2979 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2980 | |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2981 | 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] | 2982 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Rob Bradford | dfe3105 | 2013-06-26 19:49:11 +0100 | [diff] [blame] | 2983 | } else { |
| 2984 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2985 | } |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | static void |
| 2989 | remove_popup_grab(struct shell_surface *shsurf) |
| 2990 | { |
| 2991 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2992 | |
| 2993 | wl_list_remove(&shsurf->popup.grab_link); |
| 2994 | wl_list_init(&shsurf->popup.grab_link); |
| 2995 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2996 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2997 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2998 | } |
| 2999 | } |
| 3000 | |
| 3001 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3002 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3003 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3004 | struct shell_seat *shseat = shsurf->popup.shseat; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3005 | struct weston_view *parent_view = get_default_view(shsurf->parent); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3006 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3007 | shsurf->surface->output = parent_view->output; |
| 3008 | shsurf->view->output = parent_view->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3009 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3010 | weston_view_set_transform_parent(shsurf->view, parent_view); |
| 3011 | weston_view_set_position(shsurf->view, shsurf->popup.x, shsurf->popup.y); |
| 3012 | weston_view_update_transform(shsurf->view); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3013 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3014 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3015 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3016 | } else { |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3017 | shell_surface_send_popup_done(shsurf); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3018 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3019 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3020 | } |
| 3021 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3022 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3023 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3024 | shell_surface_move, |
| 3025 | shell_surface_resize, |
| 3026 | shell_surface_set_toplevel, |
| 3027 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3028 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3029 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 3030 | shell_surface_set_maximized, |
| 3031 | shell_surface_set_title, |
| 3032 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3033 | }; |
| 3034 | |
| 3035 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3036 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3037 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3038 | wl_signal_emit(&shsurf->destroy_signal, shsurf); |
| 3039 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3040 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 3041 | remove_popup_grab(shsurf); |
| 3042 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 3043 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3044 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 3045 | shell_surface_is_top_fullscreen(shsurf)) |
| 3046 | restore_output_mode (shsurf->fullscreen_output); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3047 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3048 | if (shsurf->fullscreen.black_view) |
| 3049 | weston_surface_destroy(shsurf->fullscreen.black_view->surface); |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 3050 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3051 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 3052 | * we can always remove the listener. |
| 3053 | */ |
| 3054 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 3055 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 3056 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 3057 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3058 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3059 | weston_view_destroy(shsurf->view); |
| 3060 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3061 | wl_list_remove(&shsurf->children_link); |
| 3062 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3063 | wl_list_remove(&shsurf->link); |
| 3064 | free(shsurf); |
| 3065 | } |
| 3066 | |
| 3067 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3068 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 3069 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3070 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3071 | |
| 3072 | destroy_shell_surface(shsurf); |
| 3073 | } |
| 3074 | |
| 3075 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3076 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3077 | { |
| 3078 | struct shell_surface *shsurf = container_of(listener, |
| 3079 | struct shell_surface, |
| 3080 | surface_destroy_listener); |
| 3081 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3082 | if (shsurf->resource) |
| 3083 | wl_resource_destroy(shsurf->resource); |
| 3084 | else |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3085 | destroy_shell_surface(shsurf); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3086 | } |
| 3087 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3088 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3089 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3090 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3091 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3092 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3093 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3094 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3095 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 3096 | else |
| 3097 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 3098 | } |
| 3099 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3100 | static struct shell_surface * |
| 3101 | create_common_surface(void *shell, struct weston_surface *surface, |
| 3102 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3103 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3104 | struct shell_surface *shsurf; |
| 3105 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3106 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3107 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3108 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3109 | } |
| 3110 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3111 | shsurf = calloc(1, sizeof *shsurf); |
| 3112 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3113 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3114 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3115 | } |
| 3116 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3117 | shsurf->view = weston_view_create(surface); |
| 3118 | if (!shsurf->view) { |
| 3119 | weston_log("no memory to allocate shell surface\n"); |
| 3120 | free(shsurf); |
| 3121 | return NULL; |
| 3122 | } |
| 3123 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3124 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3125 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3126 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3127 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3128 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3129 | shsurf->saved_position_valid = false; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3130 | shsurf->saved_size_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 3131 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3132 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3133 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 3134 | shsurf->fullscreen.framerate = 0; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3135 | shsurf->fullscreen.black_view = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3136 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3137 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 3138 | |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3139 | wl_signal_init(&shsurf->destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3140 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3141 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3142 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3143 | |
| 3144 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 3145 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3146 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3147 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3148 | /* empty when not in use */ |
| 3149 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 3150 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 3151 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3152 | wl_list_init(&shsurf->workspace_transform.link); |
| 3153 | |
Philip Withnall | 648a4dd | 2013-11-25 18:01:44 +0000 | [diff] [blame] | 3154 | wl_list_init(&shsurf->children_link); |
| 3155 | wl_list_init(&shsurf->children_list); |
| 3156 | shsurf->parent = NULL; |
| 3157 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3158 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3159 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3160 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3161 | shsurf->client = client; |
| 3162 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 3163 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3164 | } |
| 3165 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3166 | static struct shell_surface * |
| 3167 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 3168 | const struct weston_shell_client *client) |
| 3169 | { |
| 3170 | struct shell_surface *shsurf; |
| 3171 | shsurf = create_common_surface(shell, surface, client); |
| 3172 | |
| 3173 | shsurf->type = SHELL_SURFACE_NONE; |
| 3174 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 3175 | |
| 3176 | return shsurf; |
| 3177 | } |
| 3178 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3179 | static struct weston_view * |
| 3180 | get_primary_view(void *shell, struct shell_surface *shsurf) |
| 3181 | { |
| 3182 | return shsurf->view; |
| 3183 | } |
| 3184 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3185 | static void |
| 3186 | shell_get_shell_surface(struct wl_client *client, |
| 3187 | struct wl_resource *resource, |
| 3188 | uint32_t id, |
| 3189 | struct wl_resource *surface_resource) |
| 3190 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3191 | struct weston_surface *surface = |
| 3192 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3193 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3194 | struct shell_surface *shsurf; |
| 3195 | |
| 3196 | if (get_shell_surface(surface)) { |
| 3197 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3198 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3199 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3200 | return; |
| 3201 | } |
| 3202 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 3203 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 3204 | if (!shsurf) { |
| 3205 | wl_resource_post_error(surface_resource, |
| 3206 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3207 | "surface->configure already set"); |
| 3208 | return; |
| 3209 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3210 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3211 | shsurf->resource = |
| 3212 | wl_resource_create(client, |
| 3213 | &wl_shell_surface_interface, 1, id); |
| 3214 | wl_resource_set_implementation(shsurf->resource, |
| 3215 | &shell_surface_implementation, |
| 3216 | shsurf, shell_destroy_shell_surface); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3217 | } |
| 3218 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3219 | static bool |
| 3220 | shell_surface_is_wl_shell_surface(struct shell_surface *shsurf) |
| 3221 | { |
| 3222 | return wl_resource_instance_of(shsurf->resource, |
| 3223 | &wl_shell_surface_interface, |
| 3224 | &shell_surface_implementation); |
| 3225 | } |
| 3226 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3227 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 3228 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3229 | }; |
| 3230 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3231 | /**************************** |
| 3232 | * xdg-shell implementation */ |
| 3233 | |
| 3234 | static void |
| 3235 | xdg_surface_destroy(struct wl_client *client, |
| 3236 | struct wl_resource *resource) |
| 3237 | { |
| 3238 | wl_resource_destroy(resource); |
| 3239 | } |
| 3240 | |
| 3241 | static void |
| 3242 | xdg_surface_pong(struct wl_client *client, |
| 3243 | struct wl_resource *resource, |
| 3244 | uint32_t serial) |
| 3245 | { |
| 3246 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3247 | |
| 3248 | surface_pong(shsurf, serial); |
| 3249 | } |
| 3250 | |
| 3251 | static void |
| 3252 | xdg_surface_set_app_id(struct wl_client *client, |
| 3253 | struct wl_resource *resource, |
| 3254 | const char *app_id) |
| 3255 | { |
| 3256 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3257 | |
| 3258 | free(shsurf->class); |
| 3259 | shsurf->class = strdup(app_id); |
| 3260 | } |
| 3261 | |
| 3262 | static void |
| 3263 | xdg_surface_set_title(struct wl_client *client, |
| 3264 | struct wl_resource *resource, const char *title) |
| 3265 | { |
| 3266 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3267 | |
| 3268 | set_title(shsurf, title); |
| 3269 | } |
| 3270 | |
| 3271 | static void |
| 3272 | xdg_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 3273 | struct wl_resource *seat_resource, uint32_t serial) |
| 3274 | { |
| 3275 | common_surface_move(resource, seat_resource, serial); |
| 3276 | } |
| 3277 | |
| 3278 | static void |
| 3279 | xdg_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 3280 | struct wl_resource *seat_resource, uint32_t serial, |
| 3281 | uint32_t edges) |
| 3282 | { |
| 3283 | common_surface_resize(resource, seat_resource, serial, edges); |
| 3284 | } |
| 3285 | |
| 3286 | static void |
| 3287 | xdg_surface_set_output(struct wl_client *client, |
| 3288 | struct wl_resource *resource, |
| 3289 | struct wl_resource *output_resource) |
| 3290 | { |
| 3291 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3292 | struct weston_output *output; |
| 3293 | |
| 3294 | if (output_resource) |
| 3295 | output = wl_resource_get_user_data(output_resource); |
| 3296 | else |
| 3297 | output = NULL; |
| 3298 | |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3299 | shsurf->recommended_output = output; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | static void |
| 3303 | xdg_surface_set_fullscreen(struct wl_client *client, |
| 3304 | struct wl_resource *resource) |
| 3305 | { |
| 3306 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3307 | |
| 3308 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3309 | return; |
| 3310 | |
| 3311 | if (!shsurf->next_state.fullscreen) { |
| 3312 | shsurf->next_state.fullscreen = true; |
| 3313 | shsurf->state_changed = true; |
| 3314 | set_fullscreen(shsurf, |
| 3315 | WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3316 | 0, shsurf->recommended_output); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3317 | } |
| 3318 | } |
| 3319 | |
| 3320 | static void |
| 3321 | xdg_surface_unset_fullscreen(struct wl_client *client, |
| 3322 | struct wl_resource *resource) |
| 3323 | { |
| 3324 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3325 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3326 | |
| 3327 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3328 | return; |
| 3329 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3330 | if (!shsurf->next_state.fullscreen) |
| 3331 | return; |
| 3332 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3333 | shsurf->next_state.fullscreen = false; |
| 3334 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3335 | |
| 3336 | if (shsurf->saved_size_valid) { |
| 3337 | width = shsurf->saved_width; |
| 3338 | height = shsurf->saved_height; |
| 3339 | shsurf->saved_size_valid = false; |
| 3340 | } else { |
| 3341 | width = shsurf->surface->width; |
| 3342 | height = shsurf->surface->height; |
| 3343 | } |
| 3344 | |
| 3345 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
| 3346 | shsurf->next_type = shsurf->type; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | static void |
| 3350 | xdg_surface_set_maximized(struct wl_client *client, |
| 3351 | struct wl_resource *resource) |
| 3352 | { |
| 3353 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3354 | |
| 3355 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3356 | return; |
| 3357 | |
| 3358 | if (!shsurf->next_state.maximized) { |
| 3359 | shsurf->next_state.maximized = true; |
| 3360 | shsurf->state_changed = true; |
Rafael Antognolli | 65f98d8 | 2013-12-03 15:35:47 -0200 | [diff] [blame] | 3361 | set_maximized(shsurf, NULL); |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | static void |
| 3366 | xdg_surface_unset_maximized(struct wl_client *client, |
| 3367 | struct wl_resource *resource) |
| 3368 | { |
| 3369 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3370 | int32_t width, height; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3371 | |
| 3372 | if (shsurf->type != SHELL_SURFACE_TOPLEVEL) |
| 3373 | return; |
| 3374 | |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3375 | if (!shsurf->next_state.maximized) |
| 3376 | return; |
| 3377 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3378 | shsurf->next_state.maximized = false; |
| 3379 | shsurf->state_changed = true; |
Rafael Antognolli | 3c4e3f7 | 2013-12-03 15:35:46 -0200 | [diff] [blame] | 3380 | |
| 3381 | if (shsurf->saved_size_valid) { |
| 3382 | width = shsurf->saved_width; |
| 3383 | height = shsurf->saved_height; |
| 3384 | shsurf->saved_size_valid = false; |
| 3385 | } else { |
| 3386 | width = shsurf->surface->width; |
| 3387 | height = shsurf->surface->height; |
| 3388 | } |
| 3389 | |
| 3390 | shsurf->client->send_configure(shsurf->surface, 0, width, height); |
| 3391 | shsurf->next_type = shsurf->type; |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | static const struct xdg_surface_interface xdg_surface_implementation = { |
| 3395 | xdg_surface_destroy, |
| 3396 | xdg_surface_set_transient_for, |
| 3397 | xdg_surface_set_title, |
| 3398 | xdg_surface_set_app_id, |
| 3399 | xdg_surface_pong, |
| 3400 | xdg_surface_move, |
| 3401 | xdg_surface_resize, |
| 3402 | xdg_surface_set_output, |
| 3403 | xdg_surface_set_fullscreen, |
| 3404 | xdg_surface_unset_fullscreen, |
| 3405 | xdg_surface_set_maximized, |
| 3406 | xdg_surface_unset_maximized, |
| 3407 | NULL /* set_minimized */ |
| 3408 | }; |
| 3409 | |
| 3410 | static void |
| 3411 | xdg_send_configure(struct weston_surface *surface, |
| 3412 | uint32_t edges, int32_t width, int32_t height) |
| 3413 | { |
| 3414 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3415 | |
| 3416 | xdg_surface_send_configure(shsurf->resource, edges, width, height); |
| 3417 | } |
| 3418 | |
| 3419 | static const struct weston_shell_client xdg_client = { |
| 3420 | xdg_send_configure |
| 3421 | }; |
| 3422 | |
| 3423 | static void |
| 3424 | xdg_use_unstable_version(struct wl_client *client, |
| 3425 | struct wl_resource *resource, |
| 3426 | int32_t version) |
| 3427 | { |
| 3428 | if (version > 1) { |
| 3429 | wl_resource_post_error(resource, |
| 3430 | 1, |
| 3431 | "xdg-shell:: version not implemented yet."); |
| 3432 | return; |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | static struct shell_surface * |
| 3437 | create_xdg_surface(void *shell, struct weston_surface *surface, |
| 3438 | const struct weston_shell_client *client) |
| 3439 | { |
| 3440 | struct shell_surface *shsurf; |
| 3441 | shsurf = create_common_surface(shell, surface, client); |
| 3442 | |
| 3443 | shsurf->type = SHELL_SURFACE_NONE; |
| 3444 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
| 3445 | |
| 3446 | return shsurf; |
| 3447 | } |
| 3448 | |
| 3449 | static void |
| 3450 | xdg_get_xdg_surface(struct wl_client *client, |
| 3451 | struct wl_resource *resource, |
| 3452 | uint32_t id, |
| 3453 | struct wl_resource *surface_resource) |
| 3454 | { |
| 3455 | struct weston_surface *surface = |
| 3456 | wl_resource_get_user_data(surface_resource); |
| 3457 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3458 | struct shell_surface *shsurf; |
| 3459 | |
| 3460 | if (get_shell_surface(surface)) { |
| 3461 | wl_resource_post_error(surface_resource, |
| 3462 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3463 | "desktop_shell::get_shell_surface already requested"); |
| 3464 | return; |
| 3465 | } |
| 3466 | |
| 3467 | shsurf = create_xdg_surface(shell, surface, &xdg_client); |
| 3468 | if (!shsurf) { |
| 3469 | wl_resource_post_error(surface_resource, |
| 3470 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3471 | "surface->configure already set"); |
| 3472 | return; |
| 3473 | } |
| 3474 | |
| 3475 | shsurf->resource = |
| 3476 | wl_resource_create(client, |
| 3477 | &xdg_surface_interface, 1, id); |
| 3478 | wl_resource_set_implementation(shsurf->resource, |
| 3479 | &xdg_surface_implementation, |
| 3480 | shsurf, shell_destroy_shell_surface); |
| 3481 | } |
| 3482 | |
| 3483 | static bool |
| 3484 | shell_surface_is_xdg_surface(struct shell_surface *shsurf) |
| 3485 | { |
| 3486 | return wl_resource_instance_of(shsurf->resource, |
| 3487 | &xdg_surface_interface, |
| 3488 | &xdg_surface_implementation); |
| 3489 | } |
| 3490 | |
| 3491 | /* xdg-popup implementation */ |
| 3492 | |
| 3493 | static void |
| 3494 | xdg_popup_destroy(struct wl_client *client, |
| 3495 | struct wl_resource *resource) |
| 3496 | { |
| 3497 | wl_resource_destroy(resource); |
| 3498 | } |
| 3499 | |
| 3500 | static void |
| 3501 | xdg_popup_pong(struct wl_client *client, |
| 3502 | struct wl_resource *resource, |
| 3503 | uint32_t serial) |
| 3504 | { |
| 3505 | struct shell_surface *shsurf = wl_resource_get_user_data(resource); |
| 3506 | |
| 3507 | surface_pong(shsurf, serial); |
| 3508 | } |
| 3509 | |
| 3510 | static const struct xdg_popup_interface xdg_popup_implementation = { |
| 3511 | xdg_popup_destroy, |
| 3512 | xdg_popup_pong |
| 3513 | }; |
| 3514 | |
| 3515 | static void |
| 3516 | xdg_popup_send_configure(struct weston_surface *surface, |
| 3517 | uint32_t edges, int32_t width, int32_t height) |
| 3518 | { |
| 3519 | } |
| 3520 | |
| 3521 | static const struct weston_shell_client xdg_popup_client = { |
| 3522 | xdg_popup_send_configure |
| 3523 | }; |
| 3524 | |
| 3525 | static struct shell_surface * |
| 3526 | create_xdg_popup(void *shell, struct weston_surface *surface, |
| 3527 | const struct weston_shell_client *client, |
| 3528 | struct weston_surface *parent, |
| 3529 | struct shell_seat *seat, |
| 3530 | uint32_t serial, |
| 3531 | int32_t x, int32_t y) |
| 3532 | { |
| 3533 | struct shell_surface *shsurf; |
| 3534 | shsurf = create_common_surface(shell, surface, client); |
| 3535 | |
| 3536 | shsurf->type = SHELL_SURFACE_NONE; |
| 3537 | shsurf->next_type = SHELL_SURFACE_POPUP; |
| 3538 | shsurf->popup.shseat = seat; |
| 3539 | shsurf->popup.serial = serial; |
| 3540 | shsurf->popup.x = x; |
| 3541 | shsurf->popup.y = y; |
| 3542 | shell_surface_set_parent(shsurf, parent); |
| 3543 | |
| 3544 | return shsurf; |
| 3545 | } |
| 3546 | |
| 3547 | static void |
| 3548 | xdg_get_xdg_popup(struct wl_client *client, |
| 3549 | struct wl_resource *resource, |
| 3550 | uint32_t id, |
| 3551 | struct wl_resource *surface_resource, |
| 3552 | struct wl_resource *parent_resource, |
| 3553 | struct wl_resource *seat_resource, |
| 3554 | uint32_t serial, |
| 3555 | int32_t x, int32_t y, uint32_t flags) |
| 3556 | { |
| 3557 | struct weston_surface *surface = |
| 3558 | wl_resource_get_user_data(surface_resource); |
| 3559 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3560 | struct shell_surface *shsurf; |
| 3561 | struct weston_surface *parent; |
| 3562 | struct shell_seat *seat; |
| 3563 | |
| 3564 | if (get_shell_surface(surface)) { |
| 3565 | wl_resource_post_error(surface_resource, |
| 3566 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3567 | "desktop_shell::get_shell_surface already requested"); |
| 3568 | return; |
| 3569 | } |
| 3570 | |
| 3571 | if (!parent_resource) { |
| 3572 | wl_resource_post_error(surface_resource, |
| 3573 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3574 | "xdg_shell::get_xdg_popup requires a parent shell surface"); |
| 3575 | } |
| 3576 | |
| 3577 | parent = wl_resource_get_user_data(parent_resource); |
| 3578 | seat = get_shell_seat(wl_resource_get_user_data(seat_resource));; |
| 3579 | |
| 3580 | shsurf = create_xdg_popup(shell, surface, &xdg_popup_client, |
| 3581 | parent, seat, serial, x, y); |
| 3582 | if (!shsurf) { |
| 3583 | wl_resource_post_error(surface_resource, |
| 3584 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3585 | "surface->configure already set"); |
| 3586 | return; |
| 3587 | } |
| 3588 | |
| 3589 | shsurf->resource = |
| 3590 | wl_resource_create(client, |
| 3591 | &xdg_popup_interface, 1, id); |
| 3592 | wl_resource_set_implementation(shsurf->resource, |
| 3593 | &xdg_popup_implementation, |
| 3594 | shsurf, shell_destroy_shell_surface); |
| 3595 | } |
| 3596 | |
| 3597 | static bool |
| 3598 | shell_surface_is_xdg_popup(struct shell_surface *shsurf) |
| 3599 | { |
| 3600 | return wl_resource_instance_of(shsurf->resource, |
| 3601 | &xdg_popup_interface, |
| 3602 | &xdg_popup_implementation); |
| 3603 | } |
| 3604 | |
| 3605 | static const struct xdg_shell_interface xdg_implementation = { |
| 3606 | xdg_use_unstable_version, |
| 3607 | xdg_get_xdg_surface, |
| 3608 | xdg_get_xdg_popup |
| 3609 | }; |
| 3610 | |
| 3611 | static int |
| 3612 | xdg_shell_unversioned_dispatch(const void *implementation, |
| 3613 | void *_target, uint32_t opcode, |
| 3614 | const struct wl_message *message, |
| 3615 | union wl_argument *args) |
| 3616 | { |
| 3617 | struct wl_resource *resource = _target; |
| 3618 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
| 3619 | |
| 3620 | if (opcode != 0) { |
| 3621 | wl_resource_post_error(resource, |
| 3622 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3623 | "must call use_unstable_version first"); |
| 3624 | return 0; |
| 3625 | } |
| 3626 | |
| 3627 | #define XDG_SERVER_VERSION 1 |
| 3628 | |
| 3629 | if (args[0].i != XDG_SERVER_VERSION) { |
| 3630 | wl_resource_post_error(resource, |
| 3631 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3632 | "incompatible version, server is %d " |
| 3633 | "client wants %d", |
| 3634 | XDG_SERVER_VERSION, args[0].i); |
| 3635 | return 0; |
| 3636 | } |
| 3637 | |
| 3638 | wl_resource_set_implementation(resource, &xdg_implementation, |
| 3639 | shell, NULL); |
| 3640 | |
| 3641 | return 1; |
| 3642 | } |
| 3643 | |
| 3644 | /* end of xdg-shell implementation */ |
| 3645 | /***********************************/ |
| 3646 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3647 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3648 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 3649 | |
| 3650 | static int |
| 3651 | screensaver_timeout(void *data) |
| 3652 | { |
| 3653 | struct desktop_shell *shell = data; |
| 3654 | |
| 3655 | shell_fade(shell, FADE_OUT); |
| 3656 | |
| 3657 | return 1; |
| 3658 | } |
| 3659 | |
| 3660 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3661 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3662 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3663 | struct desktop_shell *shell = |
| 3664 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3665 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3666 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 3667 | |
| 3668 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 3669 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3673 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3674 | { |
| 3675 | if (shell->screensaver.binding) |
| 3676 | return; |
| 3677 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3678 | if (!shell->screensaver.path) { |
| 3679 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3680 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 3681 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3682 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3683 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3684 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 3685 | return; |
| 3686 | } |
| 3687 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3688 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3689 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3690 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3691 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3695 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3696 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 3697 | if (shell->screensaver.process.pid == 0) |
| 3698 | return; |
| 3699 | |
| 3700 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3704 | configure_static_view(struct weston_view *ev, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3705 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3706 | struct weston_view *v, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3707 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3708 | wl_list_for_each_safe(v, next, &layer->view_list, layer_link) { |
| 3709 | if (v->output == ev->output && v != ev) { |
| 3710 | weston_view_unmap(v); |
| 3711 | v->surface->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3712 | } |
| 3713 | } |
| 3714 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3715 | weston_view_set_position(ev, ev->output->x, ev->output->y); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3716 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3717 | if (wl_list_empty(&ev->layer_link)) { |
| 3718 | wl_list_insert(&layer->view_list, &ev->layer_link); |
| 3719 | weston_compositor_schedule_repaint(ev->surface->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3720 | } |
| 3721 | } |
| 3722 | |
| 3723 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3724 | 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] | 3725 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3726 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3727 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3728 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3729 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3730 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3731 | configure_static_view(view, &shell->background_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3735 | desktop_shell_set_background(struct wl_client *client, |
| 3736 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3737 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3738 | struct wl_resource *surface_resource) |
| 3739 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3740 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3741 | struct weston_surface *surface = |
| 3742 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3743 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3744 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3745 | if (surface->configure) { |
| 3746 | wl_resource_post_error(surface_resource, |
| 3747 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3748 | "surface role already assigned"); |
| 3749 | return; |
| 3750 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3751 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3752 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3753 | weston_view_destroy(view); |
| 3754 | view = weston_view_create(surface); |
| 3755 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 3756 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3757 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3758 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3759 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3760 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3761 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3762 | surface->output->width, |
| 3763 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3767 | 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] | 3768 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3769 | struct desktop_shell *shell = es->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3770 | struct weston_view *view; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3771 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3772 | view = container_of(es->views.next, struct weston_view, surface_link); |
| 3773 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3774 | configure_static_view(view, &shell->panel_layer); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3778 | desktop_shell_set_panel(struct wl_client *client, |
| 3779 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3780 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3781 | struct wl_resource *surface_resource) |
| 3782 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3783 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3784 | struct weston_surface *surface = |
| 3785 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3786 | struct weston_view *view, *next; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3787 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3788 | if (surface->configure) { |
| 3789 | wl_resource_post_error(surface_resource, |
| 3790 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3791 | "surface role already assigned"); |
| 3792 | return; |
| 3793 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3794 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3795 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 3796 | weston_view_destroy(view); |
| 3797 | view = weston_view_create(surface); |
| 3798 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3799 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3800 | surface->configure_private = shell; |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3801 | surface->output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3802 | view->output = surface->output; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3803 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 3804 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3805 | surface->output->width, |
| 3806 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3807 | } |
| 3808 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3809 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3810 | 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] | 3811 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3812 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3813 | struct weston_view *view; |
| 3814 | |
| 3815 | view = container_of(surface->views.next, struct weston_view, surface_link); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3816 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3817 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3818 | return; |
| 3819 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3820 | center_on_output(view, get_default_output(shell->compositor)); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3821 | |
| 3822 | if (!weston_surface_is_mapped(surface)) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3823 | wl_list_insert(&shell->lock_layer.view_list, |
| 3824 | &view->layer_link); |
| 3825 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3826 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3831 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3832 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3833 | struct desktop_shell *shell = |
| 3834 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3835 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3836 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3837 | shell->lock_surface = NULL; |
| 3838 | } |
| 3839 | |
| 3840 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3841 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 3842 | struct wl_resource *resource, |
| 3843 | struct wl_resource *surface_resource) |
| 3844 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3845 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3846 | struct weston_surface *surface = |
| 3847 | wl_resource_get_user_data(surface_resource); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3848 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3849 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3850 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3851 | if (!shell->locked) |
| 3852 | return; |
| 3853 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3854 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3855 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3856 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3857 | wl_signal_add(&surface->destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3858 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3859 | |
Kristian Høgsberg | aa2ee8b | 2013-10-30 15:49:45 -0700 | [diff] [blame] | 3860 | weston_view_create(surface); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 3861 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3862 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3866 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3867 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3868 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3869 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3870 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3871 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3872 | wl_list_remove(&shell->lock_layer.link); |
| 3873 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3874 | &shell->fullscreen_layer.link); |
| 3875 | wl_list_insert(&shell->fullscreen_layer.link, |
| 3876 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3877 | if (shell->showing_input_panels) { |
| 3878 | wl_list_insert(&shell->panel_layer.link, |
| 3879 | &shell->input_panel_layer.link); |
| 3880 | wl_list_insert(&shell->input_panel_layer.link, |
| 3881 | &ws->layer.link); |
| 3882 | } else { |
| 3883 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 3884 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3885 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 3886 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 3887 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3888 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3889 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 3890 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | static void |
| 3894 | desktop_shell_unlock(struct wl_client *client, |
| 3895 | struct wl_resource *resource) |
| 3896 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3897 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3898 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3899 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3900 | |
| 3901 | if (shell->locked) |
| 3902 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3903 | } |
| 3904 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3905 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 3906 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3907 | struct wl_resource *resource, |
| 3908 | struct wl_resource *surface_resource) |
| 3909 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3910 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3911 | |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3912 | shell->grab_surface = wl_resource_get_user_data(surface_resource); |
Kristian Høgsberg | 48588f8 | 2013-10-24 15:51:35 -0700 | [diff] [blame] | 3913 | weston_view_create(shell->grab_surface); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3914 | } |
| 3915 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3916 | static void |
| 3917 | desktop_shell_desktop_ready(struct wl_client *client, |
| 3918 | struct wl_resource *resource) |
| 3919 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 3920 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3921 | |
| 3922 | shell_fade_startup(shell); |
| 3923 | } |
| 3924 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3925 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 3926 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3927 | desktop_shell_set_panel, |
| 3928 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3929 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 3930 | desktop_shell_set_grab_surface, |
| 3931 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3932 | }; |
| 3933 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3934 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3935 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3936 | { |
| 3937 | struct shell_surface *shsurf; |
| 3938 | |
| 3939 | shsurf = get_shell_surface(surface); |
| 3940 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 3941 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3942 | return shsurf->type; |
| 3943 | } |
| 3944 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3945 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3946 | 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] | 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 | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3950 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3951 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3952 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3953 | if (surface == NULL) |
| 3954 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3955 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3956 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 3957 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 3958 | shsurf->state.maximized) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3959 | return; |
| 3960 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3961 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | static void |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame^] | 3965 | maximize_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3966 | { |
| 3967 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3968 | struct weston_surface *surface; |
| 3969 | struct shell_surface *shsurf; |
| 3970 | |
| 3971 | surface = weston_surface_get_main_surface(focus); |
| 3972 | if (surface == NULL) |
| 3973 | return; |
| 3974 | |
| 3975 | shsurf = get_shell_surface(surface); |
| 3976 | if (shsurf == NULL) |
| 3977 | return; |
| 3978 | |
| 3979 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 3980 | return; |
| 3981 | |
| 3982 | if (shsurf->state.maximized) |
| 3983 | xdg_surface_send_request_unset_maximized(shsurf->resource); |
| 3984 | else |
| 3985 | xdg_surface_send_request_set_maximized(shsurf->resource); |
| 3986 | } |
| 3987 | |
| 3988 | static void |
| 3989 | fullscreen_binding(struct weston_seat *seat, uint32_t time, uint32_t button, void *data) |
| 3990 | { |
| 3991 | struct weston_surface *focus = seat->pointer->focus->surface; |
| 3992 | struct weston_surface *surface; |
| 3993 | struct shell_surface *shsurf; |
| 3994 | |
| 3995 | surface = weston_surface_get_main_surface(focus); |
| 3996 | if (surface == NULL) |
| 3997 | return; |
| 3998 | |
| 3999 | shsurf = get_shell_surface(surface); |
| 4000 | if (shsurf == NULL) |
| 4001 | return; |
| 4002 | |
| 4003 | if (!shell_surface_is_xdg_surface(shsurf)) |
| 4004 | return; |
| 4005 | |
| 4006 | if (shsurf->state.fullscreen) |
| 4007 | xdg_surface_send_request_unset_fullscreen(shsurf->resource); |
| 4008 | else |
| 4009 | xdg_surface_send_request_set_fullscreen(shsurf->resource); |
| 4010 | } |
| 4011 | |
| 4012 | static void |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4013 | touch_move_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4014 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4015 | struct weston_surface *focus = seat->touch->focus->surface; |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4016 | struct weston_surface *surface; |
| 4017 | struct shell_surface *shsurf; |
| 4018 | |
| 4019 | surface = weston_surface_get_main_surface(focus); |
| 4020 | if (surface == NULL) |
| 4021 | return; |
| 4022 | |
| 4023 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4024 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4025 | shsurf->state.maximized) |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 4026 | return; |
| 4027 | |
| 4028 | surface_touch_move(shsurf, (struct weston_seat *) seat); |
| 4029 | } |
| 4030 | |
| 4031 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4032 | 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] | 4033 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4034 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4035 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4036 | uint32_t edges = 0; |
| 4037 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4038 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 4039 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4040 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 4041 | if (surface == NULL) |
| 4042 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4043 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4044 | shsurf = get_shell_surface(surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4045 | if (shsurf == NULL || shsurf->state.fullscreen || |
| 4046 | shsurf->state.maximized) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 4047 | return; |
| 4048 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4049 | weston_view_from_global(shsurf->view, |
| 4050 | wl_fixed_to_int(seat->pointer->grab_x), |
| 4051 | wl_fixed_to_int(seat->pointer->grab_y), |
| 4052 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4053 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4054 | if (x < shsurf->surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4055 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4056 | else if (x < 2 * shsurf->surface->width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4057 | edges |= 0; |
| 4058 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4059 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4060 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4061 | if (y < shsurf->surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4062 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4063 | else if (y < 2 * shsurf->surface->height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4064 | edges |= 0; |
| 4065 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 4066 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4067 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4068 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4072 | 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] | 4073 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4074 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4075 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4076 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4077 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4078 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4079 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4080 | /* XXX: broken for windows containing sub-surfaces */ |
| 4081 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4082 | if (surface == NULL) |
| 4083 | return; |
| 4084 | |
| 4085 | shsurf = get_shell_surface(surface); |
| 4086 | if (!shsurf) |
| 4087 | return; |
| 4088 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4089 | shsurf->view->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4090 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4091 | if (shsurf->view->alpha > 1.0) |
| 4092 | shsurf->view->alpha = 1.0; |
| 4093 | if (shsurf->view->alpha < step) |
| 4094 | shsurf->view->alpha = step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4095 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4096 | weston_view_geometry_dirty(shsurf->view); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 4097 | weston_surface_damage(surface); |
| 4098 | } |
| 4099 | |
| 4100 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4101 | 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] | 4102 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4103 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4104 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 4105 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4106 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4107 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4108 | |
| 4109 | wl_list_for_each(output, &compositor->output_list, link) { |
| 4110 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4111 | wl_fixed_to_double(seat->pointer->x), |
| 4112 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 4113 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4114 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4115 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4116 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4117 | increment = -output->zoom.increment; |
| 4118 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4119 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 4120 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 4121 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4122 | else |
| 4123 | increment = 0; |
| 4124 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 4125 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 4126 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4127 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4128 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4129 | else if (output->zoom.level > output->zoom.max_level) |
| 4130 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 4131 | else if (!output->zoom.active) { |
Giulio Camuffo | 412b024 | 2013-11-14 23:42:51 +0100 | [diff] [blame] | 4132 | weston_output_activate_zoom(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 4133 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4134 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4135 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4136 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4137 | weston_output_update_zoom(output); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4138 | } |
| 4139 | } |
| 4140 | } |
| 4141 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4142 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4143 | 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] | 4144 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4145 | { |
| 4146 | do_zoom(seat, time, 0, axis, value); |
| 4147 | } |
| 4148 | |
| 4149 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4150 | 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] | 4151 | void *data) |
| 4152 | { |
| 4153 | do_zoom(seat, time, key, 0, 0); |
| 4154 | } |
| 4155 | |
| 4156 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4157 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4158 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4159 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4160 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4161 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4162 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4163 | } |
| 4164 | |
| 4165 | static void |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4166 | lower_fullscreen_layer(struct desktop_shell *shell); |
| 4167 | |
| 4168 | struct alt_tab { |
| 4169 | struct desktop_shell *shell; |
| 4170 | struct weston_keyboard_grab grab; |
| 4171 | |
| 4172 | struct wl_list *current; |
| 4173 | |
| 4174 | struct wl_list preview_list; |
| 4175 | }; |
| 4176 | |
| 4177 | struct alt_tab_preview { |
| 4178 | struct alt_tab *alt_tab; |
| 4179 | |
| 4180 | struct weston_view *view; |
| 4181 | struct weston_transform transform; |
| 4182 | |
| 4183 | struct wl_listener listener; |
| 4184 | |
| 4185 | struct wl_list link; |
| 4186 | }; |
| 4187 | |
| 4188 | static void |
| 4189 | alt_tab_next(struct alt_tab *alt_tab) |
| 4190 | { |
| 4191 | alt_tab->current = alt_tab->current->next; |
| 4192 | |
| 4193 | /* Make sure we're not pointing to the list header e.g. after |
| 4194 | * cycling through the whole list. */ |
| 4195 | if (alt_tab->current->next == alt_tab->preview_list.next) |
| 4196 | alt_tab->current = alt_tab->current->next; |
| 4197 | } |
| 4198 | |
| 4199 | static void |
| 4200 | alt_tab_destroy(struct alt_tab *alt_tab) |
| 4201 | { |
| 4202 | struct alt_tab_preview *preview, *next; |
| 4203 | struct weston_keyboard *keyboard = alt_tab->grab.keyboard; |
| 4204 | |
| 4205 | if (alt_tab->current && alt_tab->current != &alt_tab->preview_list) { |
| 4206 | preview = wl_container_of(alt_tab->current, preview, link); |
| 4207 | |
| 4208 | activate(alt_tab->shell, preview->view->surface, |
| 4209 | (struct weston_seat *) keyboard->seat); |
| 4210 | } |
| 4211 | |
| 4212 | wl_list_for_each_safe(preview, next, &alt_tab->preview_list, link) { |
| 4213 | wl_list_remove(&preview->link); |
| 4214 | wl_list_remove(&preview->listener.link); |
| 4215 | weston_view_destroy(preview->view); |
| 4216 | free(preview); |
| 4217 | } |
| 4218 | |
| 4219 | weston_keyboard_end_grab(keyboard); |
| 4220 | if (keyboard->input_method_resource) |
| 4221 | keyboard->grab = &keyboard->input_method_grab; |
| 4222 | |
| 4223 | free(alt_tab); |
| 4224 | } |
| 4225 | |
| 4226 | static void |
| 4227 | alt_tab_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4228 | { |
| 4229 | struct alt_tab_preview *preview = |
| 4230 | container_of(listener, struct alt_tab_preview, listener); |
| 4231 | struct alt_tab *alt_tab = preview->alt_tab; |
| 4232 | int advance = 0; |
| 4233 | |
| 4234 | /* If the preview that we're removing is the currently selected one, |
| 4235 | * we want to move to the next one. So we move to ->prev and then |
| 4236 | * call _next() after removing the preview. */ |
| 4237 | if (alt_tab->current == &preview->link) { |
| 4238 | alt_tab->current = alt_tab->current->prev; |
| 4239 | advance = 1; |
| 4240 | } |
| 4241 | |
| 4242 | wl_list_remove(&preview->listener.link); |
| 4243 | wl_list_remove(&preview->link); |
| 4244 | |
| 4245 | free(preview); |
| 4246 | |
| 4247 | if (advance) |
| 4248 | alt_tab_next(alt_tab); |
| 4249 | |
| 4250 | /* If the last preview goes away, stop the alt-tab */ |
| 4251 | if (wl_list_empty(alt_tab->current)) |
| 4252 | alt_tab_destroy(alt_tab); |
| 4253 | } |
| 4254 | |
| 4255 | static void |
| 4256 | alt_tab_key(struct weston_keyboard_grab *grab, |
| 4257 | uint32_t time, uint32_t key, uint32_t state_w) |
| 4258 | { |
| 4259 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4260 | enum wl_keyboard_key_state state = state_w; |
| 4261 | |
| 4262 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
| 4263 | alt_tab_next(alt_tab); |
| 4264 | } |
| 4265 | |
| 4266 | static void |
| 4267 | alt_tab_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 4268 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4269 | uint32_t mods_locked, uint32_t group) |
| 4270 | { |
| 4271 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4272 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 4273 | |
| 4274 | if ((seat->modifier_state & MODIFIER_ALT) == 0) |
| 4275 | alt_tab_destroy(alt_tab); |
| 4276 | } |
| 4277 | |
| 4278 | static void |
| 4279 | alt_tab_cancel(struct weston_keyboard_grab *grab) |
| 4280 | { |
| 4281 | struct alt_tab *alt_tab = container_of(grab, struct alt_tab, grab); |
| 4282 | |
| 4283 | alt_tab_destroy(alt_tab); |
| 4284 | } |
| 4285 | |
| 4286 | static const struct weston_keyboard_grab_interface alt_tab_grab = { |
| 4287 | alt_tab_key, |
| 4288 | alt_tab_modifier, |
| 4289 | alt_tab_cancel, |
| 4290 | }; |
| 4291 | |
| 4292 | static int |
| 4293 | view_for_alt_tab(struct weston_view *view) |
| 4294 | { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4295 | struct shell_surface *shsurf = get_shell_surface(view->surface); |
| 4296 | if (!shsurf) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4297 | return 0; |
| 4298 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 4299 | if (shsurf->parent) |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4300 | return 0; |
| 4301 | |
| 4302 | if (view != get_default_view(view->surface)) |
| 4303 | return 0; |
| 4304 | |
| 4305 | return 1; |
| 4306 | } |
| 4307 | |
| 4308 | static void |
| 4309 | alt_tab_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
| 4310 | void *data) |
| 4311 | { |
| 4312 | struct alt_tab *alt_tab; |
| 4313 | struct desktop_shell *shell = data; |
| 4314 | struct weston_output *output = get_default_output(shell->compositor); |
| 4315 | struct workspace *ws; |
| 4316 | struct weston_view *view; |
| 4317 | int num_surfaces = 0; |
| 4318 | int x, y, side, margin; |
| 4319 | |
| 4320 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4321 | |
| 4322 | if (view_for_alt_tab(view)) |
| 4323 | num_surfaces++; |
| 4324 | } |
| 4325 | |
| 4326 | if (!num_surfaces) |
| 4327 | return; |
| 4328 | |
| 4329 | alt_tab = malloc(sizeof *alt_tab); |
| 4330 | if (!alt_tab) |
| 4331 | return; |
| 4332 | |
| 4333 | alt_tab->shell = shell; |
| 4334 | wl_list_init(&alt_tab->preview_list); |
| 4335 | alt_tab->current = &alt_tab->preview_list; |
| 4336 | |
| 4337 | restore_all_output_modes(shell->compositor); |
| 4338 | lower_fullscreen_layer(alt_tab->shell); |
| 4339 | |
| 4340 | alt_tab->grab.interface = &alt_tab_grab; |
| 4341 | weston_keyboard_start_grab(seat->keyboard, &alt_tab->grab); |
| 4342 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 4343 | |
| 4344 | ws = get_current_workspace(shell); |
| 4345 | |
| 4346 | /* FIXME: add some visual candy e.g. prelight the selected view |
| 4347 | * and/or add a black surrounding background à la gnome-shell */ |
| 4348 | |
| 4349 | /* Determine the size for each preview */ |
| 4350 | side = output->width / num_surfaces; |
| 4351 | if (side > 200) |
| 4352 | side = 200; |
| 4353 | margin = side / 4; |
| 4354 | side -= margin; |
| 4355 | |
| 4356 | x = margin; |
| 4357 | y = (output->height - side) / 2; |
| 4358 | |
| 4359 | /* Create a view for each surface */ |
| 4360 | wl_list_for_each(view, &shell->compositor->view_list, link) { |
| 4361 | struct alt_tab_preview *preview; |
| 4362 | struct weston_view *v; |
| 4363 | float scale; |
| 4364 | |
| 4365 | if (!view_for_alt_tab(view)) |
| 4366 | continue; |
| 4367 | |
| 4368 | preview = malloc(sizeof *preview); |
| 4369 | if (!preview) { |
| 4370 | alt_tab_destroy(alt_tab); |
| 4371 | return; |
| 4372 | } |
| 4373 | |
| 4374 | preview->alt_tab = alt_tab; |
| 4375 | |
| 4376 | preview->view = v = weston_view_create(view->surface); |
| 4377 | v->output = view->output; |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4378 | |
| 4379 | wl_list_remove(&v->layer_link); |
| 4380 | wl_list_insert(&ws->layer.view_list, &v->layer_link); |
| 4381 | weston_view_damage_below(v); |
| 4382 | weston_surface_damage(v->surface); |
| 4383 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4384 | weston_view_set_position(v, x, y); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4385 | |
| 4386 | preview->listener.notify = alt_tab_handle_surface_destroy; |
| 4387 | wl_signal_add(&v->destroy_signal, &preview->listener); |
| 4388 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4389 | if (view->surface->width > view->surface->height) |
| 4390 | scale = side / (float) view->surface->width; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4391 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4392 | scale = side / (float) view->surface->height; |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 4393 | |
| 4394 | wl_list_insert(&v->geometry.transformation_list, |
| 4395 | &preview->transform.link); |
| 4396 | weston_matrix_init(&preview->transform.matrix); |
| 4397 | weston_matrix_scale(&preview->transform.matrix, |
| 4398 | scale, scale, 1.0f); |
| 4399 | |
| 4400 | weston_view_geometry_dirty(v); |
| 4401 | weston_compositor_schedule_repaint(v->surface->compositor); |
| 4402 | |
| 4403 | /* Insert at the end of the list */ |
| 4404 | wl_list_insert(alt_tab->preview_list.prev, &preview->link); |
| 4405 | |
| 4406 | x += side + margin; |
| 4407 | } |
| 4408 | |
| 4409 | /* Start at the second preview so a simple <alt>tab changes window. |
| 4410 | * We set `current' to the first preview and not the second because |
| 4411 | * we're going to receive a key press callback for the initial |
| 4412 | * <alt>tab which will make `current' point to the second element. */ |
| 4413 | alt_tab_next(alt_tab); |
| 4414 | } |
| 4415 | |
| 4416 | static void |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4417 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 4418 | wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4419 | { |
| 4420 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4421 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4422 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4423 | struct shell_surface *shsurf = rotate->base.shsurf; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4424 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4425 | |
Giulio Camuffo | 1959ab8 | 2013-11-14 23:42:52 +0100 | [diff] [blame] | 4426 | weston_pointer_move(pointer, x, y); |
| 4427 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4428 | if (!shsurf) |
| 4429 | return; |
| 4430 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4431 | cx = 0.5f * shsurf->surface->width; |
| 4432 | cy = 0.5f * shsurf->surface->height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4433 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4434 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 4435 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4436 | r = sqrtf(dx * dx + dy * dy); |
| 4437 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4438 | wl_list_remove(&shsurf->rotation.transform.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4439 | weston_view_geometry_dirty(shsurf->view); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4440 | |
| 4441 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4442 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4443 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4444 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4445 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4446 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4447 | |
| 4448 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4449 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4450 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4451 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 4452 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4453 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 4454 | wl_list_insert( |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4455 | &shsurf->view->geometry.transformation_list, |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4456 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4457 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4458 | wl_list_init(&shsurf->rotation.transform.link); |
| 4459 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4460 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4461 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4462 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4463 | /* We need to adjust the position of the surface |
| 4464 | * in case it was resized in a rotated state before */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4465 | cposx = shsurf->view->geometry.x + cx; |
| 4466 | cposy = shsurf->view->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4467 | dposx = rotate->center.x - cposx; |
| 4468 | dposy = rotate->center.y - cposy; |
| 4469 | if (dposx != 0.0f || dposy != 0.0f) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4470 | weston_view_set_position(shsurf->view, |
| 4471 | shsurf->view->geometry.x + dposx, |
| 4472 | shsurf->view->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4473 | } |
| 4474 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 4475 | /* Repaint implies weston_surface_update_transform(), which |
| 4476 | * lazily applies the damage due to rotation update. |
| 4477 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4478 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4482 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 4483 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4484 | { |
| 4485 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4486 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4487 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4488 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4489 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4490 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 4491 | if (pointer->button_count == 0 && |
| 4492 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 4493 | if (shsurf) |
| 4494 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 4495 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4496 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4497 | free(rotate); |
| 4498 | } |
| 4499 | } |
| 4500 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4501 | static void |
| 4502 | rotate_grab_cancel(struct weston_pointer_grab *grab) |
| 4503 | { |
| 4504 | struct rotate_grab *rotate = |
| 4505 | container_of(grab, struct rotate_grab, base.grab); |
| 4506 | |
| 4507 | shell_grab_end(&rotate->base); |
| 4508 | free(rotate); |
| 4509 | } |
| 4510 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 4511 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4512 | noop_grab_focus, |
| 4513 | rotate_grab_motion, |
| 4514 | rotate_grab_button, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 4515 | rotate_grab_cancel, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4516 | }; |
| 4517 | |
| 4518 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4519 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4520 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4521 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 4522 | float dx, dy; |
| 4523 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4524 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4525 | rotate = malloc(sizeof *rotate); |
| 4526 | if (!rotate) |
| 4527 | return; |
| 4528 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4529 | weston_view_to_global_float(surface->view, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4530 | surface->surface->width * 0.5f, |
| 4531 | surface->surface->height * 0.5f, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4532 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4533 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4534 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 4535 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4536 | r = sqrtf(dx * dx + dy * dy); |
| 4537 | if (r > 20.0f) { |
| 4538 | struct weston_matrix inverse; |
| 4539 | |
| 4540 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4541 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4542 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 4543 | |
| 4544 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 4545 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 4546 | } else { |
| 4547 | weston_matrix_init(&surface->rotation.rotation); |
| 4548 | weston_matrix_init(&rotate->rotation); |
| 4549 | } |
| 4550 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 4551 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 4552 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4556 | 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] | 4557 | void *data) |
| 4558 | { |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4559 | struct weston_surface *focus = seat->pointer->focus->surface; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4560 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4561 | struct shell_surface *surface; |
| 4562 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4563 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4564 | if (base_surface == NULL) |
| 4565 | return; |
| 4566 | |
| 4567 | surface = get_shell_surface(base_surface); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4568 | if (surface == NULL || surface->state.fullscreen || |
| 4569 | surface->state.maximized) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4570 | return; |
| 4571 | |
| 4572 | surface_rotate(surface, seat); |
| 4573 | } |
| 4574 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4575 | /* Move all fullscreen layers down to the current workspace in a non-reversible |
| 4576 | * manner. This should be used when implementing shell-wide overlays, such as |
| 4577 | * the alt-tab switcher, which need to de-promote fullscreen layers. */ |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 4578 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4579 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 4580 | { |
| 4581 | struct workspace *ws; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4582 | struct weston_view *view, *prev; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4583 | |
| 4584 | ws = get_current_workspace(shell); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4585 | wl_list_for_each_reverse_safe(view, prev, |
| 4586 | &shell->fullscreen_layer.view_list, |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4587 | layer_link) { |
| 4588 | wl_list_remove(&view->layer_link); |
| 4589 | wl_list_insert(&ws->layer.view_list, &view->layer_link); |
| 4590 | weston_view_damage_below(view); |
| 4591 | weston_surface_damage(view->surface); |
| 4592 | } |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4596 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4597 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4598 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4599 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4600 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4601 | struct workspace *ws; |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4602 | struct weston_surface *old_es; |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4603 | struct shell_surface *shsurf; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4604 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4605 | main_surface = weston_surface_get_main_surface(es); |
| 4606 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4607 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4608 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 4609 | state = ensure_focus_state(shell, seat); |
| 4610 | if (state == NULL) |
| 4611 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4612 | |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4613 | old_es = state->keyboard_focus; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4614 | state->keyboard_focus = es; |
| 4615 | wl_list_remove(&state->surface_destroy_listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4616 | wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 4617 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 4618 | shsurf = get_shell_surface(main_surface); |
| 4619 | if (shsurf->state.fullscreen) |
| 4620 | shell_configure_fullscreen(shsurf); |
| 4621 | else |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 4622 | restore_all_output_modes(shell->compositor); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4623 | |
Philip Withnall | 83ffd9d | 2013-11-25 18:01:42 +0000 | [diff] [blame] | 4624 | if (shell->focus_animation_type != ANIMATION_NONE) { |
| 4625 | ws = get_current_workspace(shell); |
Louis-Francis Ratté-Boulianne | b482dbd | 2013-11-19 11:37:11 +0100 | [diff] [blame] | 4626 | 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] | 4627 | } |
| 4628 | |
| 4629 | /* Update the surface’s layer. This brings it to the top of the stacking |
| 4630 | * order as appropriate. */ |
| 4631 | shell_surface_update_layer(get_shell_surface(main_surface)); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4632 | } |
| 4633 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4634 | /* no-op func for checking black surface */ |
| 4635 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4636 | 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] | 4637 | { |
| 4638 | } |
| 4639 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 4640 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4641 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 4642 | { |
| 4643 | if (es->configure == black_surface_configure) { |
| 4644 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 4645 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 4646 | return true; |
| 4647 | } |
| 4648 | return false; |
| 4649 | } |
| 4650 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4651 | static void |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4652 | activate_binding(struct weston_seat *seat, |
| 4653 | struct desktop_shell *shell, |
| 4654 | struct weston_surface *focus) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4655 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4656 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4657 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 4658 | if (!focus) |
| 4659 | return; |
| 4660 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4661 | if (is_black_surface(focus, &main_surface)) |
| 4662 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 4663 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4664 | main_surface = weston_surface_get_main_surface(focus); |
| 4665 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 4666 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 4667 | |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4668 | activate(shell, focus, seat); |
| 4669 | } |
| 4670 | |
| 4671 | static void |
| 4672 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
| 4673 | void *data) |
| 4674 | { |
| 4675 | if (seat->pointer->grab != &seat->pointer->default_grab) |
| 4676 | return; |
| 4677 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4678 | activate_binding(seat, data, seat->pointer->focus->surface); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | static void |
| 4682 | touch_to_activate_binding(struct weston_seat *seat, uint32_t time, void *data) |
| 4683 | { |
| 4684 | if (seat->touch->grab != &seat->touch->default_grab) |
| 4685 | return; |
| 4686 | |
Kristian Høgsberg | 7ab139c | 2013-10-24 16:21:39 -0700 | [diff] [blame] | 4687 | activate_binding(seat, data, seat->touch->focus->surface); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4691 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4692 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4693 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4694 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4695 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4696 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4697 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4698 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4699 | |
| 4700 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4701 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4702 | /* Hide all surfaces by removing the fullscreen, panel and |
| 4703 | * toplevel layers. This way nothing else can show or receive |
| 4704 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4705 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4706 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4707 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4708 | if (shell->showing_input_panels) |
| 4709 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4710 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4711 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 4712 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4713 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4714 | launch_screensaver(shell); |
| 4715 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4716 | /* TODO: disable bindings that should not work while locked. */ |
| 4717 | |
| 4718 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4722 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4723 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 4724 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4725 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4726 | return; |
| 4727 | } |
| 4728 | |
| 4729 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 4730 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4731 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4732 | return; |
| 4733 | } |
| 4734 | |
| 4735 | if (shell->prepare_event_sent) |
| 4736 | return; |
| 4737 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4738 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 4739 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4743 | shell_fade_done(struct weston_view_animation *animation, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4744 | { |
| 4745 | struct desktop_shell *shell = data; |
| 4746 | |
| 4747 | shell->fade.animation = NULL; |
| 4748 | |
| 4749 | switch (shell->fade.type) { |
| 4750 | case FADE_IN: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4751 | weston_surface_destroy(shell->fade.view->surface); |
| 4752 | shell->fade.view = NULL; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4753 | break; |
| 4754 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4755 | lock(shell); |
| 4756 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 4757 | default: |
| 4758 | break; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4759 | } |
| 4760 | } |
| 4761 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4762 | static struct weston_view * |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4763 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4764 | { |
| 4765 | struct weston_compositor *compositor = shell->compositor; |
| 4766 | struct weston_surface *surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4767 | struct weston_view *view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4768 | |
| 4769 | surface = weston_surface_create(compositor); |
| 4770 | if (!surface) |
| 4771 | return NULL; |
| 4772 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4773 | view = weston_view_create(surface); |
| 4774 | if (!view) { |
| 4775 | weston_surface_destroy(surface); |
| 4776 | return NULL; |
| 4777 | } |
| 4778 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4779 | surface->width = 8192; |
| 4780 | surface->height = 8192; |
| 4781 | weston_view_set_position(view, 0, 0); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4782 | 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] | 4783 | wl_list_insert(&compositor->fade_layer.view_list, |
| 4784 | &view->layer_link); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4785 | pixman_region32_init(&surface->input); |
| 4786 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4787 | return view; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | static void |
| 4791 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 4792 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4793 | float tint; |
| 4794 | |
| 4795 | switch (type) { |
| 4796 | case FADE_IN: |
| 4797 | tint = 0.0; |
| 4798 | break; |
| 4799 | case FADE_OUT: |
| 4800 | tint = 1.0; |
| 4801 | break; |
| 4802 | default: |
| 4803 | weston_log("shell: invalid fade type\n"); |
| 4804 | return; |
| 4805 | } |
| 4806 | |
| 4807 | shell->fade.type = type; |
| 4808 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4809 | if (shell->fade.view == NULL) { |
| 4810 | shell->fade.view = shell_fade_create_surface(shell); |
| 4811 | if (!shell->fade.view) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4812 | return; |
| 4813 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4814 | shell->fade.view->alpha = 1.0 - tint; |
| 4815 | weston_view_update_transform(shell->fade.view); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4816 | } |
| 4817 | |
| 4818 | if (shell->fade.animation) |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4819 | weston_fade_update(shell->fade.animation, tint); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4820 | else |
| 4821 | shell->fade.animation = |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4822 | weston_fade_run(shell->fade.view, |
Kristian Høgsberg | 5281fb1 | 2013-06-17 10:10:28 -0400 | [diff] [blame] | 4823 | 1.0 - tint, tint, 300.0, |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4824 | shell_fade_done, shell); |
| 4825 | } |
| 4826 | |
| 4827 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4828 | do_shell_fade_startup(void *data) |
| 4829 | { |
| 4830 | struct desktop_shell *shell = data; |
| 4831 | |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4832 | if (shell->startup_animation_type == ANIMATION_FADE) |
| 4833 | shell_fade(shell, FADE_IN); |
| 4834 | else if (shell->startup_animation_type == ANIMATION_NONE) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4835 | weston_surface_destroy(shell->fade.view->surface); |
| 4836 | shell->fade.view = NULL; |
Kristian Høgsberg | 724c8d9 | 2013-10-16 11:38:24 -0700 | [diff] [blame] | 4837 | } |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4838 | } |
| 4839 | |
| 4840 | static void |
| 4841 | shell_fade_startup(struct desktop_shell *shell) |
| 4842 | { |
| 4843 | struct wl_event_loop *loop; |
| 4844 | |
| 4845 | if (!shell->fade.startup_timer) |
| 4846 | return; |
| 4847 | |
| 4848 | wl_event_source_remove(shell->fade.startup_timer); |
| 4849 | shell->fade.startup_timer = NULL; |
| 4850 | |
| 4851 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4852 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 4853 | } |
| 4854 | |
| 4855 | static int |
| 4856 | fade_startup_timeout(void *data) |
| 4857 | { |
| 4858 | struct desktop_shell *shell = data; |
| 4859 | |
| 4860 | shell_fade_startup(shell); |
| 4861 | return 0; |
| 4862 | } |
| 4863 | |
| 4864 | static void |
| 4865 | shell_fade_init(struct desktop_shell *shell) |
| 4866 | { |
| 4867 | /* Make compositor output all black, and wait for the desktop-shell |
| 4868 | * client to signal it is ready, then fade in. The timer triggers a |
| 4869 | * fade-in, in case the desktop-shell client takes too long. |
| 4870 | */ |
| 4871 | |
| 4872 | struct wl_event_loop *loop; |
| 4873 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4874 | if (shell->fade.view != NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4875 | weston_log("%s: warning: fade surface already exists\n", |
| 4876 | __func__); |
| 4877 | return; |
| 4878 | } |
| 4879 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4880 | shell->fade.view = shell_fade_create_surface(shell); |
| 4881 | if (!shell->fade.view) |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4882 | return; |
| 4883 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4884 | weston_view_update_transform(shell->fade.view); |
| 4885 | weston_surface_damage(shell->fade.view->surface); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 4886 | |
| 4887 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 4888 | shell->fade.startup_timer = |
| 4889 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 4890 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 4891 | } |
| 4892 | |
| 4893 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4894 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4895 | { |
| 4896 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4897 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4898 | |
| 4899 | shell_fade(shell, FADE_OUT); |
| 4900 | /* lock() is called from shell_fade_done() */ |
| 4901 | } |
| 4902 | |
| 4903 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4904 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4905 | { |
| 4906 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4907 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4908 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4909 | unlock(shell); |
| 4910 | } |
| 4911 | |
| 4912 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4913 | show_input_panels(struct wl_listener *listener, void *data) |
| 4914 | { |
| 4915 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4916 | container_of(listener, struct desktop_shell, |
| 4917 | show_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4918 | struct input_panel_surface *ipsurf, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4919 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4920 | shell->text_input.surface = (struct weston_surface*)data; |
| 4921 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 4922 | if (shell->showing_input_panels) |
| 4923 | return; |
| 4924 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4925 | shell->showing_input_panels = true; |
| 4926 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 4927 | if (!shell->locked) |
| 4928 | wl_list_insert(&shell->panel_layer.link, |
| 4929 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4930 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4931 | wl_list_for_each_safe(ipsurf, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 4932 | &shell->input_panel.surfaces, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4933 | if (!ipsurf->surface->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4934 | continue; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4935 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 4936 | &ipsurf->view->layer_link); |
| 4937 | weston_view_geometry_dirty(ipsurf->view); |
| 4938 | weston_view_update_transform(ipsurf->view); |
| 4939 | weston_surface_damage(ipsurf->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4940 | weston_slide_run(ipsurf->view, ipsurf->surface->height, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4941 | 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4942 | } |
| 4943 | } |
| 4944 | |
| 4945 | static void |
| 4946 | hide_input_panels(struct wl_listener *listener, void *data) |
| 4947 | { |
| 4948 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4949 | container_of(listener, struct desktop_shell, |
| 4950 | hide_input_panel_listener); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4951 | struct weston_view *view, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4952 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 4953 | if (!shell->showing_input_panels) |
| 4954 | return; |
| 4955 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4956 | shell->showing_input_panels = false; |
| 4957 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 4958 | if (!shell->locked) |
| 4959 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4960 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4961 | wl_list_for_each_safe(view, next, |
| 4962 | &shell->input_panel_layer.view_list, layer_link) |
| 4963 | weston_view_unmap(view); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4967 | update_input_panels(struct wl_listener *listener, void *data) |
| 4968 | { |
| 4969 | struct desktop_shell *shell = |
| 4970 | container_of(listener, struct desktop_shell, |
| 4971 | update_input_panel_listener); |
| 4972 | |
| 4973 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 4974 | } |
| 4975 | |
| 4976 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4977 | center_on_output(struct weston_view *view, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4978 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4979 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4980 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4981 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4982 | surface_subsurfaces_boundingbox(view->surface, &surf_x, &surf_y, &width, &height); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 4983 | |
| 4984 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 4985 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4986 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4987 | weston_view_set_position(view, x, y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 4988 | } |
| 4989 | |
| 4990 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4991 | weston_view_set_initial_position(struct weston_view *view, |
| 4992 | struct desktop_shell *shell) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 4993 | { |
| 4994 | struct weston_compositor *compositor = shell->compositor; |
| 4995 | int ix = 0, iy = 0; |
| 4996 | int range_x, range_y; |
| 4997 | int dx, dy, x, y, panel_height; |
| 4998 | struct weston_output *output, *target_output = NULL; |
| 4999 | struct weston_seat *seat; |
| 5000 | |
| 5001 | /* As a heuristic place the new window on the same output as the |
| 5002 | * pointer. Falling back to the output containing 0, 0. |
| 5003 | * |
| 5004 | * TODO: Do something clever for touch too? |
| 5005 | */ |
| 5006 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 5007 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5008 | ix = wl_fixed_to_int(seat->pointer->x); |
| 5009 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5010 | break; |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | wl_list_for_each(output, &compositor->output_list, link) { |
| 5015 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 5016 | target_output = output; |
| 5017 | break; |
| 5018 | } |
| 5019 | } |
| 5020 | |
| 5021 | if (!target_output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5022 | weston_view_set_position(view, 10 + random() % 400, |
| 5023 | 10 + random() % 400); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5024 | return; |
| 5025 | } |
| 5026 | |
| 5027 | /* Valid range within output where the surface will still be onscreen. |
| 5028 | * If this is negative it means that the surface is bigger than |
| 5029 | * output. |
| 5030 | */ |
| 5031 | panel_height = get_output_panel_height(shell, target_output); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5032 | range_x = target_output->width - view->surface->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5033 | range_y = (target_output->height - panel_height) - |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5034 | view->surface->height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5035 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5036 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5037 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5038 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5039 | dx = 0; |
| 5040 | |
| 5041 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5042 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 5043 | else |
| 5044 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5045 | |
| 5046 | x = target_output->x + dx; |
| 5047 | y = target_output->y + dy; |
| 5048 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5049 | weston_view_set_position(view, x, y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5053 | map(struct desktop_shell *shell, struct shell_surface *shsurf, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5054 | int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5055 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5056 | struct weston_compositor *compositor = shell->compositor; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 5057 | struct weston_seat *seat; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5058 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5059 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 5060 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5061 | /* initial positioning, see also configure() */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5062 | switch (shsurf->type) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5063 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5064 | if (shsurf->state.fullscreen) { |
| 5065 | center_on_output(shsurf->view, shsurf->fullscreen_output); |
| 5066 | shell_map_fullscreen(shsurf); |
| 5067 | } else if (shsurf->state.maximized) { |
| 5068 | /* use surface configure to set the geometry */ |
| 5069 | panel_height = get_output_panel_height(shell, shsurf->output); |
| 5070 | surface_subsurfaces_boundingbox(shsurf->surface, |
| 5071 | &surf_x, &surf_y, NULL, NULL); |
| 5072 | weston_view_set_position(shsurf->view, |
| 5073 | shsurf->output->x - surf_x, |
| 5074 | shsurf->output->y + |
| 5075 | panel_height - surf_y); |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5076 | } else if (!shsurf->state.relative) { |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5077 | weston_view_set_initial_position(shsurf->view, shell); |
| 5078 | } |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5079 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5080 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 5081 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 5082 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 5083 | case SHELL_SURFACE_NONE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5084 | weston_view_set_position(shsurf->view, |
| 5085 | shsurf->view->geometry.x + sx, |
| 5086 | shsurf->view->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 5087 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5088 | case SHELL_SURFACE_XWAYLAND: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5089 | default: |
| 5090 | ; |
| 5091 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5092 | |
Philip Withnall | e1d75ae | 2013-11-25 18:01:41 +0000 | [diff] [blame] | 5093 | /* Surface stacking order, see also activate(). */ |
| 5094 | shell_surface_update_layer(shsurf); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 5095 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5096 | if (shsurf->type != SHELL_SURFACE_NONE) { |
| 5097 | weston_view_update_transform(shsurf->view); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5098 | if (shsurf->state.maximized) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5099 | shsurf->surface->output = shsurf->output; |
| 5100 | shsurf->view->output = shsurf->output; |
| 5101 | } |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 5102 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 5103 | |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5104 | if ((shsurf->type == SHELL_SURFACE_XWAYLAND || shsurf->state.relative) && |
| 5105 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 5106 | } |
| 5107 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5108 | switch (shsurf->type) { |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5109 | /* XXX: xwayland's using the same fields for transient type */ |
| 5110 | case SHELL_SURFACE_XWAYLAND: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 5111 | if (shsurf->transient.flags == |
| 5112 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5113 | break; |
| 5114 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5115 | if (shsurf->state.relative && |
| 5116 | shsurf->transient.flags == WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 5117 | break; |
| 5118 | if (!shell->locked) |
| 5119 | break; |
| 5120 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 5121 | activate(shell, shsurf->surface, seat); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5122 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5123 | case SHELL_SURFACE_POPUP: |
| 5124 | case SHELL_SURFACE_NONE: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 5125 | default: |
| 5126 | break; |
| 5127 | } |
| 5128 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5129 | if (shsurf->type == SHELL_SURFACE_TOPLEVEL && |
| 5130 | !shsurf->state.maximized && !shsurf->state.fullscreen) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5131 | { |
| 5132 | switch (shell->win_animation_type) { |
| 5133 | case ANIMATION_FADE: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5134 | 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] | 5135 | break; |
| 5136 | case ANIMATION_ZOOM: |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5137 | weston_zoom_run(shsurf->view, 0.5, 1.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5138 | break; |
Philip Withnall | 4a86a0a | 2013-11-25 18:01:32 +0000 | [diff] [blame] | 5139 | case ANIMATION_NONE: |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 5140 | default: |
| 5141 | break; |
| 5142 | } |
| 5143 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5147 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5148 | float x, float y) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5149 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5150 | struct shell_surface *shsurf; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5151 | struct weston_view *view; |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5152 | int32_t mx, my, surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5153 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5154 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5155 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5156 | if (shsurf->state.fullscreen) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5157 | shell_configure_fullscreen(shsurf); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5158 | else if (shsurf->state.maximized) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5159 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 5160 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 5161 | NULL, NULL); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5162 | mx = shsurf->output->x - surf_x; |
| 5163 | my = shsurf->output->y + |
| 5164 | get_output_panel_height(shell,shsurf->output) - surf_y; |
| 5165 | weston_view_set_position(shsurf->view, mx, my); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5166 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5167 | weston_view_set_position(shsurf->view, x, y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 5168 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 5169 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 5170 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 5171 | if (surface->output) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5172 | wl_list_for_each(view, &surface->views, surface_link) |
| 5173 | weston_view_update_transform(view); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5174 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5175 | if (shsurf->state.maximized) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 5176 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5177 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 5178 | } |
| 5179 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5180 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5181 | 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] | 5182 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 5183 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5184 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5185 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 5186 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5187 | |
Kristian Høgsberg | 8eb0f4f | 2013-06-17 10:33:14 -0400 | [diff] [blame] | 5188 | if (!weston_surface_is_mapped(es) && |
| 5189 | !wl_list_empty(&shsurf->popup.grab_link)) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 5190 | remove_popup_grab(shsurf); |
| 5191 | } |
| 5192 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5193 | if (es->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5194 | return; |
| 5195 | |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5196 | if ((shsurf->next_type != SHELL_SURFACE_NONE && |
| 5197 | shsurf->type != shsurf->next_type) || |
| 5198 | shsurf->state_changed) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5199 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5200 | type_changed = 1; |
| 5201 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 5202 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5203 | if (!weston_surface_is_mapped(es)) { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5204 | map(shell, shsurf, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 5205 | } else if (type_changed || sx != 0 || sy != 0 || |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5206 | shsurf->last_width != es->width || |
| 5207 | shsurf->last_height != es->height) { |
| 5208 | shsurf->last_width = es->width; |
| 5209 | shsurf->last_height = es->height; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 5210 | float from_x, from_y; |
| 5211 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5212 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5213 | weston_view_to_global_float(shsurf->view, 0, 0, &from_x, &from_y); |
| 5214 | 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] | 5215 | configure(shell, es, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5216 | shsurf->view->geometry.x + to_x - from_x, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5217 | shsurf->view->geometry.y + to_y - from_y); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 5218 | } |
| 5219 | } |
| 5220 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5221 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5222 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5223 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5224 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5225 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5226 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5227 | struct desktop_shell *shell = |
| 5228 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5229 | |
| 5230 | shell->child.process.pid = 0; |
| 5231 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5232 | |
| 5233 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 5234 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 5235 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5236 | shell->child.deathstamp = time; |
| 5237 | shell->child.deathcount = 0; |
| 5238 | } |
| 5239 | |
| 5240 | shell->child.deathcount++; |
| 5241 | if (shell->child.deathcount > 5) { |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5242 | weston_log("%s died, giving up.\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5243 | return; |
| 5244 | } |
| 5245 | |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5246 | weston_log("%s died, respawning...\n", shell->client); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 5247 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5248 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5249 | } |
| 5250 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5251 | static void |
| 5252 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5253 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 5254 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5255 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5256 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5257 | &shell->child.process, |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5258 | shell->client, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 5259 | desktop_shell_sigchld); |
| 5260 | |
| 5261 | if (!shell->child.client) |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 5262 | weston_log("not able to start %s\n", shell->client); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5266 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5267 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5268 | struct desktop_shell *shell = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5269 | struct wl_resource *resource; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5270 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5271 | resource = wl_resource_create(client, &wl_shell_interface, 1, id); |
| 5272 | if (resource) |
| 5273 | wl_resource_set_implementation(resource, &shell_implementation, |
| 5274 | shell, NULL); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5275 | } |
| 5276 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5277 | static void |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 5278 | bind_xdg_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 5279 | { |
| 5280 | struct desktop_shell *shell = data; |
| 5281 | struct wl_resource *resource; |
| 5282 | |
| 5283 | resource = wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 5284 | if (resource) |
| 5285 | wl_resource_set_dispatcher(resource, |
| 5286 | xdg_shell_unversioned_dispatch, |
| 5287 | NULL, shell, NULL); |
| 5288 | } |
| 5289 | |
| 5290 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5291 | unbind_desktop_shell(struct wl_resource *resource) |
| 5292 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5293 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 5294 | |
| 5295 | if (shell->locked) |
| 5296 | resume_desktop(shell); |
| 5297 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5298 | shell->child.desktop_shell = NULL; |
| 5299 | shell->prepare_event_sent = false; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5303 | bind_desktop_shell(struct wl_client *client, |
| 5304 | void *data, uint32_t version, uint32_t id) |
| 5305 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5306 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5307 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5308 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5309 | resource = wl_resource_create(client, &desktop_shell_interface, |
| 5310 | MIN(version, 2), id); |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5311 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5312 | if (client == shell->child.client) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5313 | wl_resource_set_implementation(resource, |
| 5314 | &desktop_shell_implementation, |
| 5315 | shell, unbind_desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5316 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 5317 | |
| 5318 | if (version < 2) |
| 5319 | shell_fade_startup(shell); |
| 5320 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5321 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 5322 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 5323 | |
| 5324 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5325 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5326 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 5327 | } |
| 5328 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5329 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5330 | 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] | 5331 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5332 | struct desktop_shell *shell = surface->configure_private; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5333 | struct weston_view *view; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5334 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5335 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5336 | return; |
| 5337 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 5338 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5339 | if (!shell->locked) |
| 5340 | return; |
| 5341 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5342 | view = container_of(surface->views.next, struct weston_view, surface_link); |
| 5343 | center_on_output(view, surface->output); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5344 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5345 | if (wl_list_empty(&view->layer_link)) { |
| 5346 | wl_list_insert(shell->lock_layer.view_list.prev, |
| 5347 | &view->layer_link); |
| 5348 | weston_view_update_transform(view); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 5349 | wl_event_source_timer_update(shell->screensaver.timer, |
| 5350 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5351 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5352 | } |
| 5353 | } |
| 5354 | |
| 5355 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5356 | screensaver_set_surface(struct wl_client *client, |
| 5357 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5358 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5359 | struct wl_resource *output_resource) |
| 5360 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5361 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5362 | struct weston_surface *surface = |
| 5363 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5364 | struct weston_output *output = wl_resource_get_user_data(output_resource); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5365 | struct weston_view *view, *next; |
| 5366 | |
| 5367 | /* Make sure we only have one view */ |
| 5368 | wl_list_for_each_safe(view, next, &surface->views, surface_link) |
| 5369 | weston_view_destroy(view); |
| 5370 | weston_view_create(surface); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5371 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 5372 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5373 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5374 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | static const struct screensaver_interface screensaver_implementation = { |
| 5378 | screensaver_set_surface |
| 5379 | }; |
| 5380 | |
| 5381 | static void |
| 5382 | unbind_screensaver(struct wl_resource *resource) |
| 5383 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5384 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5385 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5386 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | static void |
| 5390 | bind_screensaver(struct wl_client *client, |
| 5391 | void *data, uint32_t version, uint32_t id) |
| 5392 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5393 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5394 | struct wl_resource *resource; |
| 5395 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5396 | resource = wl_resource_create(client, &screensaver_interface, 1, id); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5397 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5398 | if (shell->screensaver.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5399 | wl_resource_set_implementation(resource, |
| 5400 | &screensaver_implementation, |
| 5401 | shell, unbind_screensaver); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 5402 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5403 | return; |
| 5404 | } |
| 5405 | |
| 5406 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5407 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 5408 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 5409 | } |
| 5410 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5411 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5412 | 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] | 5413 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5414 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 5415 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5416 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5417 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5418 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5419 | if (surface->width == 0) |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 5420 | return; |
| 5421 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5422 | if (!weston_surface_is_mapped(surface)) { |
| 5423 | if (!shell->showing_input_panels) |
| 5424 | return; |
| 5425 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5426 | show_surface = 1; |
| 5427 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 5428 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5429 | 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] | 5430 | |
| 5431 | if (ip_surface->panel) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5432 | x = get_default_view(shell->text_input.surface)->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 5433 | 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] | 5434 | } else { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5435 | x = ip_surface->output->x + (ip_surface->output->width - surface->width) / 2; |
| 5436 | y = ip_surface->output->y + ip_surface->output->height - surface->height; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5437 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5438 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5439 | weston_view_set_position(ip_surface->view, x, y); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5440 | |
| 5441 | if (show_surface) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5442 | wl_list_insert(&shell->input_panel_layer.view_list, |
| 5443 | &ip_surface->view->layer_link); |
| 5444 | weston_view_update_transform(ip_surface->view); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5445 | weston_surface_damage(surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 5446 | 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] | 5447 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5448 | } |
| 5449 | |
| 5450 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5451 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5452 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5453 | wl_signal_emit(&input_panel_surface->destroy_signal, input_panel_surface); |
| 5454 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5455 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5456 | wl_list_remove(&input_panel_surface->link); |
| 5457 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5458 | input_panel_surface->surface->configure = NULL; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5459 | weston_view_destroy(input_panel_surface->view); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5460 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5461 | free(input_panel_surface); |
| 5462 | } |
| 5463 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5464 | static struct input_panel_surface * |
| 5465 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5466 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5467 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5468 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5469 | } else { |
| 5470 | return NULL; |
| 5471 | } |
| 5472 | } |
| 5473 | |
| 5474 | static void |
| 5475 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 5476 | { |
| 5477 | struct input_panel_surface *ipsurface = container_of(listener, |
| 5478 | struct input_panel_surface, |
| 5479 | surface_destroy_listener); |
| 5480 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5481 | if (ipsurface->resource) { |
| 5482 | wl_resource_destroy(ipsurface->resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5483 | } else { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5484 | destroy_input_panel_surface(ipsurface); |
| 5485 | } |
| 5486 | } |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5487 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5488 | static struct input_panel_surface * |
| 5489 | create_input_panel_surface(struct desktop_shell *shell, |
| 5490 | struct weston_surface *surface) |
| 5491 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5492 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5493 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5494 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 5495 | if (!input_panel_surface) |
| 5496 | return NULL; |
| 5497 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 5498 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 5499 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5500 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5501 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5502 | |
| 5503 | input_panel_surface->surface = surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5504 | input_panel_surface->view = weston_view_create(surface); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5505 | |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5506 | wl_signal_init(&input_panel_surface->destroy_signal); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5507 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5508 | wl_signal_add(&surface->destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5509 | &input_panel_surface->surface_destroy_listener); |
| 5510 | |
| 5511 | wl_list_init(&input_panel_surface->link); |
| 5512 | |
| 5513 | return input_panel_surface; |
| 5514 | } |
| 5515 | |
| 5516 | static void |
| 5517 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 5518 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 5519 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5520 | uint32_t position) |
| 5521 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5522 | struct input_panel_surface *input_panel_surface = |
| 5523 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5524 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 5525 | |
| 5526 | wl_list_insert(&shell->input_panel.surfaces, |
| 5527 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5528 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5529 | input_panel_surface->output = wl_resource_get_user_data(output_resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5530 | input_panel_surface->panel = 0; |
| 5531 | } |
| 5532 | |
| 5533 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 5534 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 5535 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5536 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5537 | struct input_panel_surface *input_panel_surface = |
| 5538 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5539 | struct desktop_shell *shell = input_panel_surface->shell; |
| 5540 | |
| 5541 | wl_list_insert(&shell->input_panel.surfaces, |
| 5542 | &input_panel_surface->link); |
| 5543 | |
| 5544 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5545 | } |
| 5546 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5547 | 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] | 5548 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 5549 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5550 | }; |
| 5551 | |
| 5552 | static void |
| 5553 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 5554 | { |
Jason Ekstrand | 51e5b14 | 2013-06-14 10:07:58 -0500 | [diff] [blame] | 5555 | struct input_panel_surface *ipsurf = |
| 5556 | wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5557 | |
| 5558 | destroy_input_panel_surface(ipsurf); |
| 5559 | } |
| 5560 | |
| 5561 | static void |
| 5562 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 5563 | struct wl_resource *resource, |
| 5564 | uint32_t id, |
| 5565 | struct wl_resource *surface_resource) |
| 5566 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 5567 | struct weston_surface *surface = |
| 5568 | wl_resource_get_user_data(surface_resource); |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5569 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5570 | struct input_panel_surface *ipsurf; |
| 5571 | |
| 5572 | if (get_input_panel_surface(surface)) { |
| 5573 | wl_resource_post_error(surface_resource, |
| 5574 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5575 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5576 | return; |
| 5577 | } |
| 5578 | |
| 5579 | ipsurf = create_input_panel_surface(shell, surface); |
| 5580 | if (!ipsurf) { |
| 5581 | wl_resource_post_error(surface_resource, |
| 5582 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5583 | "surface->configure already set"); |
| 5584 | return; |
| 5585 | } |
| 5586 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5587 | ipsurf->resource = |
| 5588 | wl_resource_create(client, |
| 5589 | &wl_input_panel_surface_interface, 1, id); |
| 5590 | wl_resource_set_implementation(ipsurf->resource, |
| 5591 | &input_panel_surface_implementation, |
| 5592 | ipsurf, |
| 5593 | destroy_input_panel_surface_resource); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5594 | } |
| 5595 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 5596 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 5597 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5598 | }; |
| 5599 | |
| 5600 | static void |
| 5601 | unbind_input_panel(struct wl_resource *resource) |
| 5602 | { |
Jason Ekstrand | 651f00e | 2013-06-14 10:07:54 -0500 | [diff] [blame] | 5603 | struct desktop_shell *shell = wl_resource_get_user_data(resource); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5604 | |
| 5605 | shell->input_panel.binding = NULL; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5606 | } |
| 5607 | |
| 5608 | static void |
| 5609 | bind_input_panel(struct wl_client *client, |
| 5610 | void *data, uint32_t version, uint32_t id) |
| 5611 | { |
| 5612 | struct desktop_shell *shell = data; |
| 5613 | struct wl_resource *resource; |
| 5614 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5615 | resource = wl_resource_create(client, |
| 5616 | &wl_input_panel_interface, 1, id); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5617 | |
| 5618 | if (shell->input_panel.binding == NULL) { |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5619 | wl_resource_set_implementation(resource, |
| 5620 | &input_panel_implementation, |
| 5621 | shell, unbind_input_panel); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5622 | shell->input_panel.binding = resource; |
| 5623 | return; |
| 5624 | } |
| 5625 | |
| 5626 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 5627 | "interface object already bound"); |
| 5628 | wl_resource_destroy(resource); |
| 5629 | } |
| 5630 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5631 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5632 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5633 | struct weston_surface *current; |
| 5634 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5635 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5636 | }; |
| 5637 | |
| 5638 | static void |
| 5639 | switcher_next(struct switcher *switcher) |
| 5640 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5641 | struct weston_view *view; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5642 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5643 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5644 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5645 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5646 | wl_list_for_each(view, &ws->layer.view_list, layer_link) { |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5647 | shsurf = get_shell_surface(view->surface); |
| 5648 | switch (shsurf->type) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5649 | case SHELL_SURFACE_TOPLEVEL: |
Rafael Antognolli | ed207b4 | 2013-12-03 15:35:43 -0200 | [diff] [blame] | 5650 | if (shsurf->parent) |
| 5651 | break; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5652 | if (first == NULL) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5653 | first = view->surface; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5654 | if (prev == switcher->current) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5655 | next = view->surface; |
| 5656 | prev = view->surface; |
| 5657 | view->alpha = 0.25; |
| 5658 | weston_view_geometry_dirty(view); |
| 5659 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5660 | break; |
Philip Withnall | 0f640e2 | 2013-11-25 18:01:31 +0000 | [diff] [blame] | 5661 | case SHELL_SURFACE_POPUP: |
| 5662 | case SHELL_SURFACE_XWAYLAND: |
| 5663 | case SHELL_SURFACE_NONE: |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5664 | default: |
| 5665 | break; |
| 5666 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5667 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5668 | if (is_black_surface(view->surface, NULL)) { |
| 5669 | view->alpha = 0.25; |
| 5670 | weston_view_geometry_dirty(view); |
| 5671 | weston_surface_damage(view->surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5672 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5673 | } |
| 5674 | |
| 5675 | if (next == NULL) |
| 5676 | next = first; |
| 5677 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5678 | if (next == NULL) |
| 5679 | return; |
| 5680 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5681 | wl_list_remove(&switcher->listener.link); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 5682 | wl_signal_add(&next->destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5683 | |
| 5684 | switcher->current = next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5685 | wl_list_for_each(view, &next->views, surface_link) |
| 5686 | view->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 5687 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 5688 | shsurf = get_shell_surface(switcher->current); |
Rafael Antognolli | 03b1659 | 2013-12-03 15:35:42 -0200 | [diff] [blame] | 5689 | if (shsurf && shsurf->state.fullscreen) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5690 | shsurf->fullscreen.black_view->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5694 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5695 | { |
| 5696 | struct switcher *switcher = |
| 5697 | container_of(listener, struct switcher, listener); |
| 5698 | |
| 5699 | switcher_next(switcher); |
| 5700 | } |
| 5701 | |
| 5702 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5703 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5704 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5705 | struct weston_view *view; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5706 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5707 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5708 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5709 | 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] | 5710 | if (is_focus_view(view)) |
| 5711 | continue; |
| 5712 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5713 | view->alpha = 1.0; |
| 5714 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5715 | } |
| 5716 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 5717 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5718 | activate(switcher->shell, switcher->current, |
| 5719 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5720 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5721 | weston_keyboard_end_grab(keyboard); |
| 5722 | if (keyboard->input_method_resource) |
| 5723 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5724 | free(switcher); |
| 5725 | } |
| 5726 | |
| 5727 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5728 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5729 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5730 | { |
| 5731 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5732 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5733 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 5734 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5735 | switcher_next(switcher); |
| 5736 | } |
| 5737 | |
| 5738 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5739 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5740 | uint32_t mods_depressed, uint32_t mods_latched, |
| 5741 | uint32_t mods_locked, uint32_t group) |
| 5742 | { |
| 5743 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 5744 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5745 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5746 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 5747 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 5748 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5749 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5750 | static void |
| 5751 | switcher_cancel(struct weston_keyboard_grab *grab) |
| 5752 | { |
| 5753 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 5754 | |
| 5755 | switcher_destroy(switcher); |
| 5756 | } |
| 5757 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5758 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 5759 | switcher_key, |
| 5760 | switcher_modifier, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 5761 | switcher_cancel, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5762 | }; |
| 5763 | |
| 5764 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 5765 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5766 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5767 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 5768 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5769 | struct switcher *switcher; |
| 5770 | |
| 5771 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5772 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5773 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 5774 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5775 | wl_list_init(&switcher->listener.link); |
| 5776 | |
Alexander Larsson | f82b6ca | 2013-05-28 16:23:39 +0200 | [diff] [blame] | 5777 | restore_all_output_modes(shell->compositor); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 5778 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5779 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 5780 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 5781 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 5782 | switcher_next(switcher); |
| 5783 | } |
| 5784 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5785 | struct exposay_surface { |
| 5786 | struct desktop_shell *shell; |
| 5787 | struct weston_surface *surface; |
| 5788 | struct weston_view *view; |
| 5789 | struct wl_list link; |
| 5790 | |
| 5791 | int x; |
| 5792 | int y; |
| 5793 | int width; |
| 5794 | int height; |
| 5795 | double scale; |
| 5796 | |
| 5797 | int row; |
| 5798 | int column; |
| 5799 | |
| 5800 | /* The animations only apply a transformation for their own lifetime, |
| 5801 | * and don't have an option to indefinitely maintain the |
| 5802 | * transformation in a steady state - so, we apply our own once the |
| 5803 | * animation has finished. */ |
| 5804 | struct weston_transform transform; |
| 5805 | }; |
| 5806 | |
| 5807 | static void exposay_set_state(struct desktop_shell *shell, |
| 5808 | enum exposay_target_state state, |
| 5809 | struct weston_seat *seat); |
| 5810 | static void exposay_check_state(struct desktop_shell *shell); |
| 5811 | |
| 5812 | static void |
| 5813 | exposay_in_flight_inc(struct desktop_shell *shell) |
| 5814 | { |
| 5815 | shell->exposay.in_flight++; |
| 5816 | } |
| 5817 | |
| 5818 | static void |
| 5819 | exposay_in_flight_dec(struct desktop_shell *shell) |
| 5820 | { |
| 5821 | if (--shell->exposay.in_flight > 0) |
| 5822 | return; |
| 5823 | |
| 5824 | exposay_check_state(shell); |
| 5825 | } |
| 5826 | |
| 5827 | static void |
| 5828 | exposay_animate_in_done(struct weston_view_animation *animation, void *data) |
| 5829 | { |
| 5830 | struct exposay_surface *esurface = data; |
| 5831 | |
| 5832 | wl_list_insert(&esurface->view->geometry.transformation_list, |
| 5833 | &esurface->transform.link); |
| 5834 | weston_matrix_init(&esurface->transform.matrix); |
| 5835 | weston_matrix_scale(&esurface->transform.matrix, |
| 5836 | esurface->scale, esurface->scale, 1.0f); |
| 5837 | weston_matrix_translate(&esurface->transform.matrix, |
| 5838 | esurface->x - esurface->view->geometry.x, |
| 5839 | esurface->y - esurface->view->geometry.y, |
| 5840 | 0); |
| 5841 | |
| 5842 | weston_view_geometry_dirty(esurface->view); |
| 5843 | weston_compositor_schedule_repaint(esurface->view->surface->compositor); |
| 5844 | |
| 5845 | exposay_in_flight_dec(esurface->shell); |
| 5846 | } |
| 5847 | |
| 5848 | static void |
| 5849 | exposay_animate_in(struct exposay_surface *esurface) |
| 5850 | { |
| 5851 | exposay_in_flight_inc(esurface->shell); |
| 5852 | |
| 5853 | weston_move_scale_run(esurface->view, |
| 5854 | esurface->x - esurface->view->geometry.x, |
| 5855 | esurface->y - esurface->view->geometry.y, |
| 5856 | 1.0, esurface->scale, 0, |
| 5857 | exposay_animate_in_done, esurface); |
| 5858 | } |
| 5859 | |
| 5860 | static void |
| 5861 | exposay_animate_out_done(struct weston_view_animation *animation, void *data) |
| 5862 | { |
| 5863 | struct exposay_surface *esurface = data; |
| 5864 | struct desktop_shell *shell = esurface->shell; |
| 5865 | |
| 5866 | wl_list_remove(&esurface->link); |
| 5867 | free(esurface); |
| 5868 | |
| 5869 | exposay_in_flight_dec(shell); |
| 5870 | } |
| 5871 | |
| 5872 | static void |
| 5873 | exposay_animate_out(struct exposay_surface *esurface) |
| 5874 | { |
| 5875 | exposay_in_flight_inc(esurface->shell); |
| 5876 | |
| 5877 | /* Remove the static transformation set up by |
| 5878 | * exposay_transform_in_done(). */ |
| 5879 | wl_list_remove(&esurface->transform.link); |
| 5880 | weston_view_geometry_dirty(esurface->view); |
| 5881 | |
| 5882 | weston_move_scale_run(esurface->view, |
| 5883 | esurface->x - esurface->view->geometry.x, |
| 5884 | esurface->y - esurface->view->geometry.y, |
| 5885 | 1.0, esurface->scale, 1, |
| 5886 | exposay_animate_out_done, esurface); |
| 5887 | } |
| 5888 | |
| 5889 | static void |
| 5890 | exposay_highlight_surface(struct desktop_shell *shell, |
| 5891 | struct exposay_surface *esurface) |
| 5892 | { |
| 5893 | struct weston_view *view = NULL; |
| 5894 | |
| 5895 | if (esurface) { |
| 5896 | shell->exposay.row_current = esurface->row; |
| 5897 | shell->exposay.column_current = esurface->column; |
| 5898 | view = esurface->view; |
| 5899 | } |
| 5900 | |
Emilio Pozuelo Monfort | 5c22ce6 | 2013-11-19 11:37:18 +0100 | [diff] [blame] | 5901 | activate(shell, view->surface, shell->exposay.seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 5902 | shell->exposay.focus_current = view; |
| 5903 | } |
| 5904 | |
| 5905 | static int |
| 5906 | exposay_is_animating(struct desktop_shell *shell) |
| 5907 | { |
| 5908 | if (shell->exposay.state_cur == EXPOSAY_LAYOUT_INACTIVE || |
| 5909 | shell->exposay.state_cur == EXPOSAY_LAYOUT_OVERVIEW) |
| 5910 | return 0; |
| 5911 | |
| 5912 | return (shell->exposay.in_flight > 0); |
| 5913 | } |
| 5914 | |
| 5915 | static void |
| 5916 | exposay_pick(struct desktop_shell *shell, int x, int y) |
| 5917 | { |
| 5918 | struct exposay_surface *esurface; |
| 5919 | |
| 5920 | if (exposay_is_animating(shell)) |
| 5921 | return; |
| 5922 | |
| 5923 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 5924 | if (x < esurface->x || x > esurface->x + esurface->width) |
| 5925 | continue; |
| 5926 | if (y < esurface->y || y > esurface->y + esurface->height) |
| 5927 | continue; |
| 5928 | |
| 5929 | exposay_highlight_surface(shell, esurface); |
| 5930 | return; |
| 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | /* Pretty lame layout for now; just tries to make a square. Should take |
| 5935 | * aspect ratio into account really. Also needs to be notified of surface |
| 5936 | * addition and removal and adjust layout/animate accordingly. */ |
| 5937 | static enum exposay_layout_state |
| 5938 | exposay_layout(struct desktop_shell *shell) |
| 5939 | { |
| 5940 | struct workspace *workspace = shell->exposay.workspace; |
| 5941 | struct weston_compositor *compositor = shell->compositor; |
| 5942 | struct weston_output *output = get_default_output(compositor); |
| 5943 | struct weston_view *view; |
| 5944 | struct exposay_surface *esurface; |
| 5945 | int w, h; |
| 5946 | int i; |
| 5947 | int last_row_removed = 0; |
| 5948 | |
| 5949 | wl_list_init(&shell->exposay.surface_list); |
| 5950 | |
| 5951 | shell->exposay.num_surfaces = 0; |
| 5952 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 5953 | if (!get_shell_surface(view->surface)) |
| 5954 | continue; |
| 5955 | shell->exposay.num_surfaces++; |
| 5956 | } |
| 5957 | |
| 5958 | if (shell->exposay.num_surfaces == 0) { |
| 5959 | shell->exposay.grid_size = 0; |
| 5960 | shell->exposay.hpadding_outer = 0; |
| 5961 | shell->exposay.vpadding_outer = 0; |
| 5962 | shell->exposay.padding_inner = 0; |
| 5963 | shell->exposay.surface_size = 0; |
| 5964 | return EXPOSAY_LAYOUT_OVERVIEW; |
| 5965 | } |
| 5966 | |
| 5967 | /* Lay the grid out as square as possible, losing surfaces from the |
| 5968 | * bottom row if required. Start with fixed padding of a 10% margin |
| 5969 | * around the outside and 80px internal padding between surfaces, and |
| 5970 | * maximise the area made available to surfaces after this, but only |
| 5971 | * to a maximum of 1/3rd the total output size. |
| 5972 | * |
| 5973 | * If we can't make a square grid, add one extra row at the bottom |
| 5974 | * which will have a smaller number of columns. |
| 5975 | * |
| 5976 | * XXX: Surely there has to be a better way to express this maths, |
| 5977 | * right?! |
| 5978 | */ |
| 5979 | shell->exposay.grid_size = floor(sqrtf(shell->exposay.num_surfaces)); |
| 5980 | if (pow(shell->exposay.grid_size, 2) != shell->exposay.num_surfaces) |
| 5981 | shell->exposay.grid_size++; |
| 5982 | last_row_removed = pow(shell->exposay.grid_size, 2) - shell->exposay.num_surfaces; |
| 5983 | |
| 5984 | shell->exposay.hpadding_outer = (output->width / 10); |
| 5985 | shell->exposay.vpadding_outer = (output->height / 10); |
| 5986 | shell->exposay.padding_inner = 80; |
| 5987 | |
| 5988 | w = output->width - (shell->exposay.hpadding_outer * 2); |
| 5989 | w -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5990 | w /= shell->exposay.grid_size; |
| 5991 | |
| 5992 | h = output->height - (shell->exposay.vpadding_outer * 2); |
| 5993 | h -= shell->exposay.padding_inner * (shell->exposay.grid_size - 1); |
| 5994 | h /= shell->exposay.grid_size; |
| 5995 | |
| 5996 | shell->exposay.surface_size = (w < h) ? w : h; |
| 5997 | if (shell->exposay.surface_size > (output->width / 2)) |
| 5998 | shell->exposay.surface_size = output->width / 2; |
| 5999 | if (shell->exposay.surface_size > (output->height / 2)) |
| 6000 | shell->exposay.surface_size = output->height / 2; |
| 6001 | |
| 6002 | i = 0; |
| 6003 | wl_list_for_each(view, &workspace->layer.view_list, layer_link) { |
| 6004 | int pad; |
| 6005 | |
| 6006 | pad = shell->exposay.surface_size + shell->exposay.padding_inner; |
| 6007 | |
| 6008 | if (!get_shell_surface(view->surface)) |
| 6009 | continue; |
| 6010 | |
| 6011 | esurface = malloc(sizeof(*esurface)); |
| 6012 | if (!esurface) { |
| 6013 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, |
| 6014 | shell->exposay.seat); |
| 6015 | break; |
| 6016 | } |
| 6017 | |
| 6018 | wl_list_insert(&shell->exposay.surface_list, &esurface->link); |
| 6019 | esurface->shell = shell; |
| 6020 | esurface->view = view; |
| 6021 | |
| 6022 | esurface->row = i / shell->exposay.grid_size; |
| 6023 | esurface->column = i % shell->exposay.grid_size; |
| 6024 | |
| 6025 | esurface->x = shell->exposay.hpadding_outer; |
| 6026 | esurface->x += pad * esurface->column; |
| 6027 | esurface->y = shell->exposay.vpadding_outer; |
| 6028 | esurface->y += pad * esurface->row; |
| 6029 | |
| 6030 | if (esurface->row == shell->exposay.grid_size - 1) |
| 6031 | esurface->x += (shell->exposay.surface_size + shell->exposay.padding_inner) * last_row_removed / 2; |
| 6032 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 6033 | if (view->surface->width > view->surface->height) |
| 6034 | esurface->scale = shell->exposay.surface_size / (float) view->surface->width; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6035 | else |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 6036 | esurface->scale = shell->exposay.surface_size / (float) view->surface->height; |
| 6037 | esurface->width = view->surface->width * esurface->scale; |
| 6038 | esurface->height = view->surface->height * esurface->scale; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6039 | |
| 6040 | if (shell->exposay.focus_current == esurface->view) |
| 6041 | exposay_highlight_surface(shell, esurface); |
| 6042 | |
| 6043 | exposay_animate_in(esurface); |
| 6044 | |
| 6045 | i++; |
| 6046 | } |
| 6047 | |
| 6048 | weston_compositor_schedule_repaint(shell->compositor); |
| 6049 | |
| 6050 | return EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW; |
| 6051 | } |
| 6052 | |
| 6053 | static void |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 6054 | exposay_motion(struct weston_pointer_grab *grab, uint32_t time, |
| 6055 | wl_fixed_t x, wl_fixed_t y) |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6056 | { |
| 6057 | struct desktop_shell *shell = |
| 6058 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 6059 | |
Emilio Pozuelo Monfort | 17467d6 | 2013-11-19 12:14:53 +0100 | [diff] [blame] | 6060 | weston_pointer_move(grab->pointer, x, y); |
| 6061 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6062 | exposay_pick(shell, |
| 6063 | wl_fixed_to_int(grab->pointer->x), |
| 6064 | wl_fixed_to_int(grab->pointer->y)); |
| 6065 | } |
| 6066 | |
| 6067 | static void |
| 6068 | exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button, |
| 6069 | uint32_t state_w) |
| 6070 | { |
| 6071 | struct desktop_shell *shell = |
| 6072 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 6073 | struct weston_seat *seat = grab->pointer->seat; |
| 6074 | enum wl_pointer_button_state state = state_w; |
| 6075 | |
| 6076 | if (button != BTN_LEFT) |
| 6077 | return; |
| 6078 | |
| 6079 | /* Store the surface we clicked on, and don't do anything if we end up |
| 6080 | * releasing on a different surface. */ |
| 6081 | if (state == WL_POINTER_BUTTON_STATE_PRESSED) { |
| 6082 | shell->exposay.clicked = shell->exposay.focus_current; |
| 6083 | return; |
| 6084 | } |
| 6085 | |
| 6086 | if (shell->exposay.focus_current == shell->exposay.clicked) |
| 6087 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 6088 | else |
| 6089 | shell->exposay.clicked = NULL; |
| 6090 | } |
| 6091 | |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 6092 | static void |
| 6093 | exposay_pointer_grab_cancel(struct weston_pointer_grab *grab) |
| 6094 | { |
| 6095 | struct desktop_shell *shell = |
| 6096 | container_of(grab, struct desktop_shell, exposay.grab_ptr); |
| 6097 | |
| 6098 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 6099 | } |
| 6100 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6101 | static const struct weston_pointer_grab_interface exposay_ptr_grab = { |
| 6102 | noop_grab_focus, |
| 6103 | exposay_motion, |
| 6104 | exposay_button, |
Emilio Pozuelo Monfort | 234c524 | 2013-11-26 13:32:08 +0100 | [diff] [blame] | 6105 | exposay_pointer_grab_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6106 | }; |
| 6107 | |
| 6108 | static int |
| 6109 | exposay_maybe_move(struct desktop_shell *shell, int row, int column) |
| 6110 | { |
| 6111 | struct exposay_surface *esurface; |
| 6112 | |
| 6113 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) { |
| 6114 | if (esurface->row != row || esurface->column != column) |
| 6115 | continue; |
| 6116 | |
| 6117 | exposay_highlight_surface(shell, esurface); |
| 6118 | return 1; |
| 6119 | } |
| 6120 | |
| 6121 | return 0; |
| 6122 | } |
| 6123 | |
| 6124 | static void |
| 6125 | exposay_key(struct weston_keyboard_grab *grab, uint32_t time, uint32_t key, |
| 6126 | uint32_t state_w) |
| 6127 | { |
| 6128 | struct weston_seat *seat = grab->keyboard->seat; |
| 6129 | struct desktop_shell *shell = |
| 6130 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 6131 | enum wl_keyboard_key_state state = state_w; |
| 6132 | |
| 6133 | if (state != WL_KEYBOARD_KEY_STATE_RELEASED) |
| 6134 | return; |
| 6135 | |
| 6136 | switch (key) { |
| 6137 | case KEY_ESC: |
| 6138 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 6139 | break; |
| 6140 | case KEY_ENTER: |
| 6141 | exposay_set_state(shell, EXPOSAY_TARGET_SWITCH, seat); |
| 6142 | break; |
| 6143 | case KEY_UP: |
| 6144 | exposay_maybe_move(shell, shell->exposay.row_current - 1, |
| 6145 | shell->exposay.column_current); |
| 6146 | break; |
| 6147 | case KEY_DOWN: |
| 6148 | /* Special case for trying to move to the bottom row when it |
| 6149 | * has fewer items than all the others. */ |
| 6150 | if (!exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 6151 | shell->exposay.column_current) && |
| 6152 | shell->exposay.row_current < (shell->exposay.grid_size - 1)) { |
| 6153 | exposay_maybe_move(shell, shell->exposay.row_current + 1, |
| 6154 | (shell->exposay.num_surfaces % |
| 6155 | shell->exposay.grid_size) - 1); |
| 6156 | } |
| 6157 | break; |
| 6158 | case KEY_LEFT: |
| 6159 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 6160 | shell->exposay.column_current - 1); |
| 6161 | break; |
| 6162 | case KEY_RIGHT: |
| 6163 | exposay_maybe_move(shell, shell->exposay.row_current, |
| 6164 | shell->exposay.column_current + 1); |
| 6165 | break; |
| 6166 | case KEY_TAB: |
| 6167 | /* Try to move right, then down (and to the leftmost column), |
| 6168 | * then if all else fails, to the top left. */ |
| 6169 | if (!exposay_maybe_move(shell, shell->exposay.row_current, |
| 6170 | shell->exposay.column_current + 1) && |
| 6171 | !exposay_maybe_move(shell, shell->exposay.row_current + 1, 0)) |
| 6172 | exposay_maybe_move(shell, 0, 0); |
| 6173 | break; |
| 6174 | default: |
| 6175 | break; |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | static void |
| 6180 | exposay_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
| 6181 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6182 | uint32_t mods_locked, uint32_t group) |
| 6183 | { |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 6184 | struct desktop_shell *shell = |
| 6185 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 6186 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
| 6187 | |
| 6188 | /* We want to know when mod has been pressed and released. |
| 6189 | * FIXME: There is a problem here: if mod is pressed, then a key |
| 6190 | * is pressed and released, then mod is released, we will treat that |
| 6191 | * as if only mod had been pressed and released. */ |
| 6192 | if (seat->modifier_state) { |
| 6193 | if (seat->modifier_state == shell->binding_modifier) { |
| 6194 | shell->exposay.mod_pressed = true; |
| 6195 | } else { |
| 6196 | shell->exposay.mod_invalid = true; |
| 6197 | } |
| 6198 | } else { |
| 6199 | if (shell->exposay.mod_pressed && !shell->exposay.mod_invalid) |
| 6200 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, seat); |
| 6201 | |
| 6202 | shell->exposay.mod_invalid = false; |
| 6203 | shell->exposay.mod_pressed = false; |
| 6204 | } |
| 6205 | |
| 6206 | return; |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6207 | } |
| 6208 | |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 6209 | static void |
| 6210 | exposay_cancel(struct weston_keyboard_grab *grab) |
| 6211 | { |
| 6212 | struct desktop_shell *shell = |
| 6213 | container_of(grab, struct desktop_shell, exposay.grab_kbd); |
| 6214 | |
| 6215 | exposay_set_state(shell, EXPOSAY_TARGET_CANCEL, shell->exposay.seat); |
| 6216 | } |
| 6217 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6218 | static const struct weston_keyboard_grab_interface exposay_kbd_grab = { |
| 6219 | exposay_key, |
| 6220 | exposay_modifier, |
Emilio Pozuelo Monfort | 8224309 | 2013-11-19 11:37:17 +0100 | [diff] [blame] | 6221 | exposay_cancel, |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6222 | }; |
| 6223 | |
| 6224 | /** |
| 6225 | * Called when the transition from overview -> inactive has completed. |
| 6226 | */ |
| 6227 | static enum exposay_layout_state |
| 6228 | exposay_set_inactive(struct desktop_shell *shell) |
| 6229 | { |
| 6230 | struct weston_seat *seat = shell->exposay.seat; |
| 6231 | |
| 6232 | weston_keyboard_end_grab(seat->keyboard); |
| 6233 | weston_pointer_end_grab(seat->pointer); |
| 6234 | if (seat->keyboard->input_method_resource) |
| 6235 | seat->keyboard->grab = &seat->keyboard->input_method_grab; |
| 6236 | |
| 6237 | return EXPOSAY_LAYOUT_INACTIVE; |
| 6238 | } |
| 6239 | |
| 6240 | /** |
| 6241 | * Begins the transition from overview to inactive. */ |
| 6242 | static enum exposay_layout_state |
| 6243 | exposay_transition_inactive(struct desktop_shell *shell, int switch_focus) |
| 6244 | { |
| 6245 | struct exposay_surface *esurface; |
| 6246 | |
| 6247 | /* Call activate() before we start the animations to avoid |
| 6248 | * animating back the old state and then immediately transitioning |
| 6249 | * to the new. */ |
| 6250 | if (switch_focus && shell->exposay.focus_current) |
| 6251 | activate(shell, shell->exposay.focus_current->surface, |
| 6252 | shell->exposay.seat); |
| 6253 | else if (shell->exposay.focus_prev) |
| 6254 | activate(shell, shell->exposay.focus_prev->surface, |
| 6255 | shell->exposay.seat); |
| 6256 | |
| 6257 | wl_list_for_each(esurface, &shell->exposay.surface_list, link) |
| 6258 | exposay_animate_out(esurface); |
| 6259 | weston_compositor_schedule_repaint(shell->compositor); |
| 6260 | |
| 6261 | return EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE; |
| 6262 | } |
| 6263 | |
| 6264 | static enum exposay_layout_state |
| 6265 | exposay_transition_active(struct desktop_shell *shell) |
| 6266 | { |
| 6267 | struct weston_seat *seat = shell->exposay.seat; |
| 6268 | |
| 6269 | shell->exposay.workspace = get_current_workspace(shell); |
| 6270 | shell->exposay.focus_prev = get_default_view (seat->keyboard->focus); |
| 6271 | shell->exposay.focus_current = get_default_view (seat->keyboard->focus); |
| 6272 | shell->exposay.clicked = NULL; |
| 6273 | wl_list_init(&shell->exposay.surface_list); |
| 6274 | |
| 6275 | lower_fullscreen_layer(shell); |
| 6276 | shell->exposay.grab_kbd.interface = &exposay_kbd_grab; |
| 6277 | weston_keyboard_start_grab(seat->keyboard, |
| 6278 | &shell->exposay.grab_kbd); |
| 6279 | weston_keyboard_set_focus(seat->keyboard, NULL); |
| 6280 | |
| 6281 | shell->exposay.grab_ptr.interface = &exposay_ptr_grab; |
| 6282 | weston_pointer_start_grab(seat->pointer, |
| 6283 | &shell->exposay.grab_ptr); |
| 6284 | weston_pointer_set_focus(seat->pointer, NULL, |
| 6285 | seat->pointer->x, seat->pointer->y); |
| 6286 | |
| 6287 | return exposay_layout(shell); |
| 6288 | } |
| 6289 | |
| 6290 | static void |
| 6291 | exposay_check_state(struct desktop_shell *shell) |
| 6292 | { |
| 6293 | enum exposay_layout_state state_new = shell->exposay.state_cur; |
| 6294 | int do_switch = 0; |
| 6295 | |
| 6296 | /* Don't do anything whilst animations are running, just store up |
| 6297 | * target state changes and only act on them when the animations have |
| 6298 | * completed. */ |
| 6299 | if (exposay_is_animating(shell)) |
| 6300 | return; |
| 6301 | |
| 6302 | switch (shell->exposay.state_target) { |
| 6303 | case EXPOSAY_TARGET_OVERVIEW: |
| 6304 | switch (shell->exposay.state_cur) { |
| 6305 | case EXPOSAY_LAYOUT_OVERVIEW: |
| 6306 | goto out; |
| 6307 | case EXPOSAY_LAYOUT_ANIMATE_TO_OVERVIEW: |
| 6308 | state_new = EXPOSAY_LAYOUT_OVERVIEW; |
| 6309 | break; |
| 6310 | default: |
| 6311 | state_new = exposay_transition_active(shell); |
| 6312 | break; |
| 6313 | } |
| 6314 | break; |
| 6315 | |
| 6316 | case EXPOSAY_TARGET_SWITCH: |
| 6317 | do_switch = 1; /* fallthrough */ |
| 6318 | case EXPOSAY_TARGET_CANCEL: |
| 6319 | switch (shell->exposay.state_cur) { |
| 6320 | case EXPOSAY_LAYOUT_INACTIVE: |
| 6321 | goto out; |
| 6322 | case EXPOSAY_LAYOUT_ANIMATE_TO_INACTIVE: |
| 6323 | state_new = exposay_set_inactive(shell); |
| 6324 | break; |
| 6325 | default: |
| 6326 | state_new = exposay_transition_inactive(shell, do_switch); |
| 6327 | break; |
| 6328 | } |
| 6329 | |
| 6330 | break; |
| 6331 | } |
| 6332 | |
| 6333 | out: |
| 6334 | shell->exposay.state_cur = state_new; |
| 6335 | } |
| 6336 | |
| 6337 | static void |
| 6338 | exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, |
| 6339 | struct weston_seat *seat) |
| 6340 | { |
| 6341 | shell->exposay.state_target = state; |
| 6342 | shell->exposay.seat = seat; |
| 6343 | exposay_check_state(shell); |
| 6344 | } |
| 6345 | |
| 6346 | static void |
| 6347 | exposay_binding(struct weston_seat *seat, enum weston_keyboard_modifier modifier, |
| 6348 | void *data) |
| 6349 | { |
| 6350 | struct desktop_shell *shell = data; |
| 6351 | |
Emilio Pozuelo Monfort | eed9344 | 2013-11-27 10:49:08 +0100 | [diff] [blame] | 6352 | exposay_set_state(shell, EXPOSAY_TARGET_OVERVIEW, seat); |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6353 | } |
| 6354 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6355 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6356 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6357 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6358 | { |
| 6359 | struct weston_compositor *compositor = data; |
| 6360 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6361 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6362 | |
| 6363 | /* TODO: we're limiting to simple use cases, where we assume just |
| 6364 | * control on the primary display. We'd have to extend later if we |
| 6365 | * ever get support for setting backlights on random desktop LCD |
| 6366 | * panels though */ |
| 6367 | output = get_default_output(compositor); |
| 6368 | if (!output) |
| 6369 | return; |
| 6370 | |
| 6371 | if (!output->set_backlight) |
| 6372 | return; |
| 6373 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6374 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 6375 | backlight_new = output->backlight_current - 25; |
| 6376 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 6377 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6378 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 6379 | if (backlight_new < 5) |
| 6380 | backlight_new = 5; |
| 6381 | if (backlight_new > 255) |
| 6382 | backlight_new = 255; |
| 6383 | |
| 6384 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 6385 | output->set_backlight(output, output->backlight_current); |
| 6386 | } |
| 6387 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6388 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6389 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6390 | struct weston_seat *seat; |
| 6391 | uint32_t key[2]; |
| 6392 | int key_released[2]; |
| 6393 | }; |
| 6394 | |
| 6395 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6396 | 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] | 6397 | uint32_t key, uint32_t state) |
| 6398 | { |
| 6399 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
Rob Bradford | 880ebc7 | 2013-07-22 17:31:38 +0100 | [diff] [blame] | 6400 | struct weston_compositor *ec = db->seat->compositor; |
| 6401 | struct wl_display *display = ec->wl_display; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6402 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6403 | uint32_t serial; |
| 6404 | int send = 0, terminate = 0; |
| 6405 | int check_binding = 1; |
| 6406 | int i; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6407 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6408 | |
| 6409 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 6410 | /* Do not run bindings on key releases */ |
| 6411 | check_binding = 0; |
| 6412 | |
| 6413 | for (i = 0; i < 2; i++) |
| 6414 | if (key == db->key[i]) |
| 6415 | db->key_released[i] = 1; |
| 6416 | |
| 6417 | if (db->key_released[0] && db->key_released[1]) { |
| 6418 | /* All key releases been swalled so end the grab */ |
| 6419 | terminate = 1; |
| 6420 | } else if (key != db->key[0] && key != db->key[1]) { |
| 6421 | /* Should not swallow release of other keys */ |
| 6422 | send = 1; |
| 6423 | } |
| 6424 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 6425 | /* Do not check bindings for the first press of the binding |
| 6426 | * key. This allows it to be used as a debug shortcut. |
| 6427 | * We still need to swallow this event. */ |
| 6428 | check_binding = 0; |
| 6429 | } else if (db->key[1]) { |
| 6430 | /* If we already ran a binding don't process another one since |
| 6431 | * we can't keep track of all the binding keys that were |
| 6432 | * pressed in order to swallow the release events. */ |
| 6433 | send = 1; |
| 6434 | check_binding = 0; |
| 6435 | } |
| 6436 | |
| 6437 | if (check_binding) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6438 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 6439 | key, state)) { |
| 6440 | /* We ran a binding so swallow the press and keep the |
| 6441 | * grab to swallow the released too. */ |
| 6442 | send = 0; |
| 6443 | terminate = 0; |
| 6444 | db->key[1] = key; |
| 6445 | } else { |
| 6446 | /* Terminate the grab since the key pressed is not a |
| 6447 | * debug binding key. */ |
| 6448 | send = 1; |
| 6449 | terminate = 1; |
| 6450 | } |
| 6451 | } |
| 6452 | |
| 6453 | if (send) { |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6454 | serial = wl_display_next_serial(display); |
| 6455 | resource_list = &grab->keyboard->focus_resource_list; |
| 6456 | wl_resource_for_each(resource, resource_list) { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6457 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 6458 | } |
| 6459 | } |
| 6460 | |
| 6461 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6462 | weston_keyboard_end_grab(grab->keyboard); |
| 6463 | if (grab->keyboard->input_method_resource) |
| 6464 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6465 | free(db); |
| 6466 | } |
| 6467 | } |
| 6468 | |
| 6469 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6470 | 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] | 6471 | uint32_t mods_depressed, uint32_t mods_latched, |
| 6472 | uint32_t mods_locked, uint32_t group) |
| 6473 | { |
| 6474 | struct wl_resource *resource; |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6475 | struct wl_list *resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6476 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6477 | resource_list = &grab->keyboard->focus_resource_list; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6478 | |
Neil Roberts | 96d790e | 2013-09-19 17:32:00 +0100 | [diff] [blame] | 6479 | wl_resource_for_each(resource, resource_list) { |
| 6480 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 6481 | mods_latched, mods_locked, group); |
| 6482 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6483 | } |
| 6484 | |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6485 | static void |
| 6486 | debug_binding_cancel(struct weston_keyboard_grab *grab) |
| 6487 | { |
| 6488 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 6489 | |
| 6490 | weston_keyboard_end_grab(grab->keyboard); |
| 6491 | free(db); |
| 6492 | } |
| 6493 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6494 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6495 | debug_binding_key, |
Jonas Ådahl | 1ea343e | 2013-10-25 23:18:05 +0200 | [diff] [blame] | 6496 | debug_binding_modifiers, |
| 6497 | debug_binding_cancel, |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6498 | }; |
| 6499 | |
| 6500 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6501 | 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] | 6502 | { |
| 6503 | struct debug_binding_grab *grab; |
| 6504 | |
| 6505 | grab = calloc(1, sizeof *grab); |
| 6506 | if (!grab) |
| 6507 | return; |
| 6508 | |
| 6509 | grab->seat = (struct weston_seat *) seat; |
| 6510 | grab->key[0] = key; |
| 6511 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 6512 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6513 | } |
| 6514 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 6515 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6516 | 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] | 6517 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6518 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 6519 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6520 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6521 | struct desktop_shell *shell = data; |
| 6522 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6523 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6524 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 6525 | focus_surface = seat->keyboard->focus; |
| 6526 | if (!focus_surface) |
| 6527 | return; |
| 6528 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6529 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 6530 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 6531 | client = wl_resource_get_client(focus_surface->resource); |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 6532 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 6533 | |
| 6534 | /* Skip clients that we launched ourselves (the credentials of |
| 6535 | * the socketpair is ours) */ |
| 6536 | if (pid == getpid()) |
| 6537 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6538 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6539 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 6540 | } |
| 6541 | |
| 6542 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6543 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6544 | uint32_t key, void *data) |
| 6545 | { |
| 6546 | struct desktop_shell *shell = data; |
| 6547 | unsigned int new_index = shell->workspaces.current; |
| 6548 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6549 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6550 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6551 | if (new_index != 0) |
| 6552 | new_index--; |
| 6553 | |
| 6554 | change_workspace(shell, new_index); |
| 6555 | } |
| 6556 | |
| 6557 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6558 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6559 | uint32_t key, void *data) |
| 6560 | { |
| 6561 | struct desktop_shell *shell = data; |
| 6562 | unsigned int new_index = shell->workspaces.current; |
| 6563 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6564 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6565 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6566 | if (new_index < shell->workspaces.num - 1) |
| 6567 | new_index++; |
| 6568 | |
| 6569 | change_workspace(shell, new_index); |
| 6570 | } |
| 6571 | |
| 6572 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6573 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6574 | uint32_t key, void *data) |
| 6575 | { |
| 6576 | struct desktop_shell *shell = data; |
| 6577 | unsigned int new_index; |
| 6578 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 6579 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 6580 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6581 | new_index = key - KEY_F1; |
| 6582 | if (new_index >= shell->workspaces.num) |
| 6583 | new_index = shell->workspaces.num - 1; |
| 6584 | |
| 6585 | change_workspace(shell, new_index); |
| 6586 | } |
| 6587 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6588 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6589 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6590 | uint32_t key, void *data) |
| 6591 | { |
| 6592 | struct desktop_shell *shell = data; |
| 6593 | unsigned int new_index = shell->workspaces.current; |
| 6594 | |
| 6595 | if (shell->locked) |
| 6596 | return; |
| 6597 | |
| 6598 | if (new_index != 0) |
| 6599 | new_index--; |
| 6600 | |
| 6601 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6602 | } |
| 6603 | |
| 6604 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 6605 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6606 | uint32_t key, void *data) |
| 6607 | { |
| 6608 | struct desktop_shell *shell = data; |
| 6609 | unsigned int new_index = shell->workspaces.current; |
| 6610 | |
| 6611 | if (shell->locked) |
| 6612 | return; |
| 6613 | |
| 6614 | if (new_index < shell->workspaces.num - 1) |
| 6615 | new_index++; |
| 6616 | |
| 6617 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 6618 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6619 | |
| 6620 | static void |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6621 | handle_output_destroy(struct wl_listener *listener, void *data) |
| 6622 | { |
| 6623 | struct shell_output *output_listener = |
| 6624 | container_of(listener, struct shell_output, destroy_listener); |
| 6625 | |
| 6626 | wl_list_remove(&output_listener->destroy_listener.link); |
| 6627 | wl_list_remove(&output_listener->link); |
| 6628 | free(output_listener); |
| 6629 | } |
| 6630 | |
| 6631 | static void |
| 6632 | create_shell_output(struct desktop_shell *shell, |
| 6633 | struct weston_output *output) |
| 6634 | { |
| 6635 | struct shell_output *shell_output; |
| 6636 | |
| 6637 | shell_output = zalloc(sizeof *shell_output); |
| 6638 | if (shell_output == NULL) |
| 6639 | return; |
| 6640 | |
| 6641 | shell_output->output = output; |
| 6642 | shell_output->shell = shell; |
| 6643 | shell_output->destroy_listener.notify = handle_output_destroy; |
| 6644 | wl_signal_add(&output->destroy_signal, |
| 6645 | &shell_output->destroy_listener); |
Kristian Høgsberg | a3a0e18 | 2013-10-23 23:36:04 -0700 | [diff] [blame] | 6646 | wl_list_insert(shell->output_list.prev, &shell_output->link); |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | static void |
| 6650 | handle_output_create(struct wl_listener *listener, void *data) |
| 6651 | { |
| 6652 | struct desktop_shell *shell = |
| 6653 | container_of(listener, struct desktop_shell, output_create_listener); |
| 6654 | struct weston_output *output = (struct weston_output *)data; |
| 6655 | |
| 6656 | create_shell_output(shell, output); |
| 6657 | } |
| 6658 | |
| 6659 | static void |
| 6660 | setup_output_destroy_handler(struct weston_compositor *ec, |
| 6661 | struct desktop_shell *shell) |
| 6662 | { |
| 6663 | struct weston_output *output; |
| 6664 | |
| 6665 | wl_list_init(&shell->output_list); |
| 6666 | wl_list_for_each(output, &ec->output_list, link) |
| 6667 | create_shell_output(shell, output); |
| 6668 | |
| 6669 | shell->output_create_listener.notify = handle_output_create; |
| 6670 | wl_signal_add(&ec->output_created_signal, |
| 6671 | &shell->output_create_listener); |
| 6672 | } |
| 6673 | |
| 6674 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6675 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6676 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6677 | struct desktop_shell *shell = |
| 6678 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6679 | struct workspace **ws; |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6680 | struct shell_output *shell_output, *tmp; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6681 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 6682 | if (shell->child.client) |
| 6683 | wl_client_destroy(shell->child.client); |
| 6684 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6685 | wl_list_remove(&shell->idle_listener.link); |
| 6686 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6687 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 6688 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 6689 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6690 | wl_list_for_each_safe(shell_output, tmp, &shell->output_list, link) { |
| 6691 | wl_list_remove(&shell_output->destroy_listener.link); |
| 6692 | wl_list_remove(&shell_output->link); |
| 6693 | free(shell_output); |
| 6694 | } |
| 6695 | |
| 6696 | wl_list_remove(&shell->output_create_listener.link); |
| 6697 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6698 | wl_array_for_each(ws, &shell->workspaces.array) |
| 6699 | workspace_destroy(*ws); |
| 6700 | wl_array_release(&shell->workspaces.array); |
| 6701 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6702 | free(shell->screensaver.path); |
Emilio Pozuelo Monfort | 46ce798 | 2013-11-20 13:22:29 +0100 | [diff] [blame] | 6703 | free(shell->client); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 6704 | free(shell); |
| 6705 | } |
| 6706 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6707 | static void |
| 6708 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 6709 | { |
| 6710 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6711 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6712 | |
| 6713 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6714 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 6715 | MODIFIER_CTRL | MODIFIER_ALT, |
| 6716 | terminate_binding, ec); |
Emilio Pozuelo Monfort | 03251b6 | 2013-11-19 11:37:16 +0100 | [diff] [blame] | 6717 | weston_compositor_add_key_binding(ec, KEY_TAB, |
| 6718 | MODIFIER_ALT, |
| 6719 | alt_tab_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6720 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 6721 | click_to_activate_binding, |
| 6722 | shell); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6723 | weston_compositor_add_touch_binding(ec, 0, |
| 6724 | touch_to_activate_binding, |
| 6725 | shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6726 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6727 | MODIFIER_SUPER | MODIFIER_ALT, |
| 6728 | surface_opacity_binding, NULL); |
| 6729 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 6730 | MODIFIER_SUPER, zoom_axis_binding, |
| 6731 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6732 | |
| 6733 | /* configurable bindings */ |
| 6734 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6735 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 6736 | zoom_key_binding, NULL); |
| 6737 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 6738 | zoom_key_binding, NULL); |
Rafael Antognolli | ea997ac | 2013-12-03 15:35:48 -0200 | [diff] [blame^] | 6739 | weston_compositor_add_key_binding(ec, KEY_M, mod, maximize_binding, |
| 6740 | NULL); |
| 6741 | weston_compositor_add_key_binding(ec, KEY_F, mod, fullscreen_binding, |
| 6742 | NULL); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6743 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 6744 | shell); |
Neil Roberts | aba0f25 | 2013-10-03 16:43:05 +0100 | [diff] [blame] | 6745 | weston_compositor_add_touch_binding(ec, mod, touch_move_binding, shell); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6746 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 6747 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 6748 | |
| 6749 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 6750 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 6751 | rotate_binding, NULL); |
| 6752 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6753 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 6754 | shell); |
| 6755 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 6756 | ec); |
| 6757 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 6758 | backlight_binding, ec); |
| 6759 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 6760 | ec); |
| 6761 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 6762 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6763 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 6764 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6765 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 6766 | workspace_up_binding, shell); |
| 6767 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 6768 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6769 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 6770 | workspace_move_surface_up_binding, |
| 6771 | shell); |
| 6772 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 6773 | workspace_move_surface_down_binding, |
| 6774 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6775 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6776 | weston_compositor_add_modifier_binding(ec, mod, exposay_binding, shell); |
| 6777 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6778 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 6779 | if (shell->workspaces.num > 1) { |
| 6780 | num_workspace_bindings = shell->workspaces.num; |
| 6781 | if (num_workspace_bindings > 6) |
| 6782 | num_workspace_bindings = 6; |
| 6783 | for (i = 0; i < num_workspace_bindings; i++) |
| 6784 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 6785 | workspace_f_binding, |
| 6786 | shell); |
| 6787 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6788 | |
| 6789 | /* Debug bindings */ |
| 6790 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 6791 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6792 | } |
| 6793 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6794 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 6795 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6796 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6797 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6798 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 6799 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6800 | struct workspace **pws; |
| 6801 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6802 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6803 | |
Peter Hutterer | f3d6227 | 2013-08-08 11:57:05 +1000 | [diff] [blame] | 6804 | shell = zalloc(sizeof *shell); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 6805 | if (shell == NULL) |
| 6806 | return -1; |
| 6807 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6808 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6809 | |
| 6810 | shell->destroy_listener.notify = shell_destroy; |
| 6811 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6812 | shell->idle_listener.notify = idle_handler; |
| 6813 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 6814 | shell->wake_listener.notify = wake_handler; |
| 6815 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6816 | shell->show_input_panel_listener.notify = show_input_panels; |
| 6817 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 6818 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 6819 | 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] | 6820 | shell->update_input_panel_listener.notify = update_input_panels; |
| 6821 | 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] | 6822 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 6823 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6824 | ec->shell_interface.create_shell_surface = create_shell_surface; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6825 | ec->shell_interface.get_primary_view = get_primary_view; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 6826 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 6827 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 6828 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6829 | ec->shell_interface.set_xwayland = set_xwayland; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 6830 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 6831 | ec->shell_interface.resize = surface_resize; |
Giulio Camuffo | 62942ad | 2013-09-11 18:20:47 +0200 | [diff] [blame] | 6832 | ec->shell_interface.set_title = set_title; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6833 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6834 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 6835 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6836 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 6837 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6838 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 6839 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 6840 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6841 | |
| 6842 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6843 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 6844 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 6845 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 6846 | |
Daniel Stone | df8133b | 2013-11-19 11:37:14 +0100 | [diff] [blame] | 6847 | shell->exposay.state_cur = EXPOSAY_LAYOUT_INACTIVE; |
| 6848 | shell->exposay.state_target = EXPOSAY_TARGET_CANCEL; |
| 6849 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 6850 | for (i = 0; i < shell->workspaces.num; i++) { |
| 6851 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 6852 | if (pws == NULL) |
| 6853 | return -1; |
| 6854 | |
| 6855 | *pws = workspace_create(); |
| 6856 | if (*pws == NULL) |
| 6857 | return -1; |
| 6858 | } |
| 6859 | activate_workspace(shell, 0); |
| 6860 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 6861 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 6862 | wl_list_init(&shell->workspaces.animation.link); |
| 6863 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 6864 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6865 | if (wl_global_create(ec->wl_display, &wl_shell_interface, 1, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 6866 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6867 | return -1; |
| 6868 | |
Rafael Antognolli | e2a3455 | 2013-12-03 15:35:45 -0200 | [diff] [blame] | 6869 | if (wl_global_create(ec->wl_display, &xdg_shell_interface, 1, |
| 6870 | shell, bind_xdg_shell) == NULL) |
| 6871 | return -1; |
| 6872 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6873 | if (wl_global_create(ec->wl_display, |
| 6874 | &desktop_shell_interface, 2, |
| 6875 | shell, bind_desktop_shell) == NULL) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 6876 | return -1; |
| 6877 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6878 | if (wl_global_create(ec->wl_display, &screensaver_interface, 1, |
| 6879 | shell, bind_screensaver) == NULL) |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 6880 | return -1; |
| 6881 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6882 | 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] | 6883 | shell, bind_input_panel) == NULL) |
| 6884 | return -1; |
| 6885 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6886 | if (wl_global_create(ec->wl_display, &workspace_manager_interface, 1, |
| 6887 | shell, bind_workspace_manager) == NULL) |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 6888 | return -1; |
| 6889 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 6890 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6891 | |
Xiong Zhang | 6b48142 | 2013-10-23 13:58:32 +0800 | [diff] [blame] | 6892 | setup_output_destroy_handler(ec, shell); |
| 6893 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 6894 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6895 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 6896 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 6897 | shell->screensaver.timer = |
| 6898 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 6899 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 6900 | wl_list_for_each(seat, &ec->seat_list, link) |
| 6901 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 6902 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 6903 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 6904 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame] | 6905 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 6906 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 6907 | return 0; |
| 6908 | } |