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. |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4 | * |
| 5 | * Permission to use, copy, modify, distribute, and sell this software and |
| 6 | * its documentation for any purpose is hereby granted without fee, provided |
| 7 | * that the above copyright notice appear in all copies and that both that |
| 8 | * copyright notice and this permission notice appear in supporting |
| 9 | * documentation, and that the name of the copyright holders not be used in |
| 10 | * advertising or publicity pertaining to distribution of the software |
| 11 | * without specific, written prior permission. The copyright holders make |
| 12 | * no representations about the suitability of this software for any |
| 13 | * purpose. It is provided "as is" without express or implied warranty. |
| 14 | * |
| 15 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 16 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 19 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 20 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 21 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <stdlib.h> |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 25 | #include <stdio.h> |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 26 | #include <stdbool.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 27 | #include <string.h> |
| 28 | #include <unistd.h> |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 29 | #include <linux/input.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 30 | #include <assert.h> |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 31 | #include <signal.h> |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 32 | #include <math.h> |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 33 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 34 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 35 | #include <wayland-server.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 37 | #include "desktop-shell-server-protocol.h" |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 38 | #include "input-method-server-protocol.h" |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 39 | #include "workspaces-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 40 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 41 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 42 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 43 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 44 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 45 | enum animation_type { |
| 46 | ANIMATION_NONE, |
| 47 | |
| 48 | ANIMATION_ZOOM, |
| 49 | ANIMATION_FADE |
| 50 | }; |
| 51 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 52 | enum fade_type { |
| 53 | FADE_IN, |
| 54 | FADE_OUT |
| 55 | }; |
| 56 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 57 | struct focus_state { |
| 58 | struct weston_seat *seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 59 | struct workspace *ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 60 | struct weston_surface *keyboard_focus; |
| 61 | struct wl_list link; |
| 62 | struct wl_listener seat_destroy_listener; |
| 63 | struct wl_listener surface_destroy_listener; |
| 64 | }; |
| 65 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 66 | struct workspace { |
| 67 | struct weston_layer layer; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 68 | |
| 69 | struct wl_list focus_list; |
| 70 | struct wl_listener seat_destroyed_listener; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 71 | }; |
| 72 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 73 | struct input_panel_surface { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 74 | struct wl_resource resource; |
| 75 | |
| 76 | struct desktop_shell *shell; |
| 77 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 78 | struct wl_list link; |
| 79 | struct weston_surface *surface; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 80 | struct wl_listener surface_destroy_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 81 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 82 | struct weston_output *output; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 83 | uint32_t panel; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 86 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 87 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 88 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 89 | struct wl_listener idle_listener; |
| 90 | struct wl_listener wake_listener; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 91 | struct wl_listener destroy_listener; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 92 | struct wl_listener show_input_panel_listener; |
| 93 | struct wl_listener hide_input_panel_listener; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 94 | struct wl_listener update_input_panel_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 95 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 96 | struct weston_layer fullscreen_layer; |
| 97 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 98 | struct weston_layer background_layer; |
| 99 | struct weston_layer lock_layer; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 100 | struct weston_layer input_panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 101 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 102 | struct wl_listener pointer_focus_listener; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 103 | struct weston_surface *grab_surface; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 104 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 105 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 106 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 107 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 108 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 109 | |
| 110 | unsigned deathcount; |
| 111 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 112 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 113 | |
| 114 | bool locked; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 115 | bool showing_input_panels; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 116 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 117 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 118 | struct { |
| 119 | struct weston_surface *surface; |
| 120 | pixman_box32_t cursor_rectangle; |
| 121 | } text_input; |
| 122 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 123 | struct weston_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 124 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 125 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 126 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 127 | struct wl_array array; |
| 128 | unsigned int current; |
| 129 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 130 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 131 | struct wl_list client_list; |
| 132 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 133 | struct weston_animation animation; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 134 | struct wl_list anim_sticky_list; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 135 | int anim_dir; |
| 136 | uint32_t anim_timestamp; |
| 137 | double anim_current; |
| 138 | struct workspace *anim_from; |
| 139 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 140 | } workspaces; |
| 141 | |
| 142 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 143 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 144 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 145 | struct wl_resource *binding; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 146 | struct weston_process process; |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 147 | struct wl_event_source *timer; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 148 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 149 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 150 | struct { |
| 151 | struct wl_resource *binding; |
| 152 | struct wl_list surfaces; |
| 153 | } input_panel; |
| 154 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 155 | struct { |
| 156 | struct weston_surface *surface; |
| 157 | struct weston_surface_animation *animation; |
| 158 | enum fade_type type; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 159 | struct wl_event_source *startup_timer; |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 160 | } fade; |
| 161 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 162 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 163 | enum animation_type win_animation_type; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 164 | }; |
| 165 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 166 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 167 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 168 | SHELL_SURFACE_TOPLEVEL, |
| 169 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 170 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 171 | SHELL_SURFACE_MAXIMIZED, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 172 | SHELL_SURFACE_POPUP |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 173 | }; |
| 174 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 175 | struct ping_timer { |
| 176 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 177 | uint32_t serial; |
| 178 | }; |
| 179 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 180 | struct shell_surface { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 181 | struct wl_resource resource; |
| 182 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 183 | struct weston_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 184 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 185 | struct weston_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 186 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 187 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 188 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 189 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 190 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 191 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 192 | bool saved_rotation_valid; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 193 | int unresponsive; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 194 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 195 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 196 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 197 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 198 | } rotation; |
| 199 | |
| 200 | struct { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 201 | struct wl_list grab_link; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 202 | int32_t x, y; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 203 | struct shell_seat *shseat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 204 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 205 | } popup; |
| 206 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 207 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 208 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 209 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 210 | } transient; |
| 211 | |
| 212 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 213 | enum wl_shell_surface_fullscreen_method type; |
| 214 | struct weston_transform transform; /* matrix from x, y */ |
| 215 | uint32_t framerate; |
| 216 | struct weston_surface *black_surface; |
| 217 | } fullscreen; |
| 218 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 219 | struct ping_timer *ping_timer; |
| 220 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 221 | struct weston_transform workspace_transform; |
| 222 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 223 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 224 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 225 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 226 | |
| 227 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 228 | }; |
| 229 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 230 | struct shell_grab { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 231 | struct weston_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 232 | struct shell_surface *shsurf; |
| 233 | struct wl_listener shsurf_destroy_listener; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 234 | struct weston_pointer *pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | struct weston_move_grab { |
| 238 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 239 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 240 | }; |
| 241 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 242 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 243 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 244 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 245 | struct { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 246 | float x; |
| 247 | float y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 248 | } center; |
| 249 | }; |
| 250 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 251 | struct shell_seat { |
| 252 | struct weston_seat *seat; |
| 253 | struct wl_listener seat_destroy_listener; |
| 254 | |
| 255 | struct { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 256 | struct weston_pointer_grab grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 257 | struct wl_list surfaces_list; |
| 258 | struct wl_client *client; |
| 259 | int32_t initial_up; |
| 260 | } popup_grab; |
| 261 | }; |
| 262 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 263 | static void |
| 264 | activate(struct desktop_shell *shell, struct weston_surface *es, |
| 265 | struct weston_seat *seat); |
| 266 | |
| 267 | static struct workspace * |
| 268 | get_current_workspace(struct desktop_shell *shell); |
| 269 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 270 | static struct shell_surface * |
| 271 | get_shell_surface(struct weston_surface *surface); |
| 272 | |
| 273 | static struct desktop_shell * |
| 274 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 275 | |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 276 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 277 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 278 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 279 | static void |
| 280 | shell_fade_startup(struct desktop_shell *shell); |
| 281 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 282 | static bool |
| 283 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 284 | { |
| 285 | struct desktop_shell *shell; |
| 286 | struct weston_surface *top_fs_es; |
| 287 | |
| 288 | shell = shell_surface_get_shell(shsurf); |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 289 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 290 | if (wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 291 | return false; |
| 292 | |
| 293 | top_fs_es = container_of(shell->fullscreen_layer.surface_list.next, |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 294 | struct weston_surface, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 295 | layer_link); |
| 296 | return (shsurf == get_shell_surface(top_fs_es)); |
| 297 | } |
| 298 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 299 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 300 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 301 | { |
| 302 | struct shell_grab *grab; |
| 303 | |
| 304 | grab = container_of(listener, struct shell_grab, |
| 305 | shsurf_destroy_listener); |
| 306 | |
| 307 | grab->shsurf = NULL; |
| 308 | } |
| 309 | |
| 310 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 311 | popup_grab_end(struct weston_pointer *pointer); |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 312 | |
| 313 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 314 | shell_grab_start(struct shell_grab *grab, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 315 | const struct weston_pointer_grab_interface *interface, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 316 | struct shell_surface *shsurf, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 317 | struct weston_pointer *pointer, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 318 | enum desktop_shell_cursor cursor) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 319 | { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 320 | struct desktop_shell *shell = shsurf->shell; |
| 321 | |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 322 | popup_grab_end(pointer); |
| 323 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 324 | grab->grab.interface = interface; |
| 325 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 326 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 327 | wl_signal_add(&shsurf->resource.destroy_signal, |
| 328 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 329 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 330 | grab->pointer = pointer; |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 331 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 332 | weston_pointer_start_grab(pointer, &grab->grab); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 333 | desktop_shell_send_grab_cursor(shell->child.desktop_shell, cursor); |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 334 | weston_pointer_set_focus(pointer, shell->grab_surface, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 335 | wl_fixed_from_int(0), wl_fixed_from_int(0)); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 339 | shell_grab_end(struct shell_grab *grab) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 340 | { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 341 | if (grab->shsurf) |
| 342 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 343 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 344 | weston_pointer_end_grab(grab->pointer); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 348 | center_on_output(struct weston_surface *surface, |
| 349 | struct weston_output *output); |
| 350 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 351 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 352 | get_modifier(char *modifier) |
| 353 | { |
| 354 | if (!modifier) |
| 355 | return MODIFIER_SUPER; |
| 356 | |
| 357 | if (!strcmp("ctrl", modifier)) |
| 358 | return MODIFIER_CTRL; |
| 359 | else if (!strcmp("alt", modifier)) |
| 360 | return MODIFIER_ALT; |
| 361 | else if (!strcmp("super", modifier)) |
| 362 | return MODIFIER_SUPER; |
| 363 | else |
| 364 | return MODIFIER_SUPER; |
| 365 | } |
| 366 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 367 | static enum animation_type |
| 368 | get_animation_type(char *animation) |
| 369 | { |
| 370 | if (!animation) |
| 371 | return ANIMATION_NONE; |
| 372 | |
| 373 | if (!strcmp("zoom", animation)) |
| 374 | return ANIMATION_ZOOM; |
| 375 | else if (!strcmp("fade", animation)) |
| 376 | return ANIMATION_FADE; |
| 377 | else |
| 378 | return ANIMATION_NONE; |
| 379 | } |
| 380 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 381 | static void |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 382 | shell_configuration(struct desktop_shell *shell, int config_fd) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 383 | { |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 384 | char *path = NULL; |
| 385 | int duration = 60; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 386 | unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 387 | char *modifier = NULL; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 388 | char *win_animation = NULL; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 389 | |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 390 | struct config_key shell_keys[] = { |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 391 | { "binding-modifier", CONFIG_KEY_STRING, &modifier }, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 392 | { "animation", CONFIG_KEY_STRING, &win_animation}, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 393 | { "num-workspaces", |
| 394 | CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 395 | }; |
| 396 | |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 397 | struct config_key saver_keys[] = { |
| 398 | { "path", CONFIG_KEY_STRING, &path }, |
| 399 | { "duration", CONFIG_KEY_INTEGER, &duration }, |
| 400 | }; |
| 401 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 402 | struct config_section cs[] = { |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 403 | { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 404 | { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL }, |
| 405 | }; |
| 406 | |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 407 | parse_config_file(config_fd, cs, ARRAY_LENGTH(cs), shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 408 | |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 409 | shell->screensaver.path = path; |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 410 | shell->screensaver.duration = duration * 1000; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 411 | shell->binding_modifier = get_modifier(modifier); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 412 | shell->win_animation_type = get_animation_type(win_animation); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 413 | shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1; |
| 414 | } |
| 415 | |
| 416 | static void |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 417 | focus_state_destroy(struct focus_state *state) |
| 418 | { |
| 419 | wl_list_remove(&state->seat_destroy_listener.link); |
| 420 | wl_list_remove(&state->surface_destroy_listener.link); |
| 421 | free(state); |
| 422 | } |
| 423 | |
| 424 | static void |
| 425 | focus_state_seat_destroy(struct wl_listener *listener, void *data) |
| 426 | { |
| 427 | struct focus_state *state = container_of(listener, |
| 428 | struct focus_state, |
| 429 | seat_destroy_listener); |
| 430 | |
| 431 | wl_list_remove(&state->link); |
| 432 | focus_state_destroy(state); |
| 433 | } |
| 434 | |
| 435 | static void |
| 436 | focus_state_surface_destroy(struct wl_listener *listener, void *data) |
| 437 | { |
| 438 | struct focus_state *state = container_of(listener, |
| 439 | struct focus_state, |
Kristian Høgsberg | b8e0d0f | 2012-07-31 10:30:26 -0400 | [diff] [blame] | 440 | surface_destroy_listener); |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 441 | struct desktop_shell *shell; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 442 | struct weston_surface *main_surface; |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 443 | struct weston_surface *surface, *next; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 444 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 445 | main_surface = weston_surface_get_main_surface(state->keyboard_focus); |
| 446 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 447 | next = NULL; |
| 448 | wl_list_for_each(surface, &state->ws->layer.surface_list, layer_link) { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 449 | if (surface == main_surface) |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 450 | continue; |
| 451 | |
| 452 | next = surface; |
| 453 | break; |
| 454 | } |
| 455 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 456 | /* if the focus was a sub-surface, activate its main surface */ |
| 457 | if (main_surface != state->keyboard_focus) |
| 458 | next = main_surface; |
| 459 | |
Kristian Høgsberg | e377822 | 2012-07-31 17:29:30 -0400 | [diff] [blame] | 460 | if (next) { |
| 461 | shell = state->seat->compositor->shell_interface.shell; |
| 462 | activate(shell, next, state->seat); |
| 463 | } else { |
| 464 | wl_list_remove(&state->link); |
| 465 | focus_state_destroy(state); |
| 466 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static struct focus_state * |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 470 | focus_state_create(struct weston_seat *seat, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 471 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 472 | struct focus_state *state; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 473 | |
| 474 | state = malloc(sizeof *state); |
| 475 | if (state == NULL) |
| 476 | return NULL; |
| 477 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 478 | state->ws = ws; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 479 | state->seat = seat; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 480 | wl_list_insert(&ws->focus_list, &state->link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 481 | |
| 482 | state->seat_destroy_listener.notify = focus_state_seat_destroy; |
| 483 | state->surface_destroy_listener.notify = focus_state_surface_destroy; |
Kristian Høgsberg | 4912454 | 2013-05-06 22:27:40 -0400 | [diff] [blame] | 484 | wl_signal_add(&seat->destroy_signal, |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 485 | &state->seat_destroy_listener); |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 486 | wl_list_init(&state->surface_destroy_listener.link); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 487 | |
| 488 | return state; |
| 489 | } |
| 490 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 491 | static struct focus_state * |
| 492 | ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat) |
| 493 | { |
| 494 | struct workspace *ws = get_current_workspace(shell); |
| 495 | struct focus_state *state; |
| 496 | |
| 497 | wl_list_for_each(state, &ws->focus_list, link) |
| 498 | if (state->seat == seat) |
| 499 | break; |
| 500 | |
| 501 | if (&state->link == &ws->focus_list) |
| 502 | state = focus_state_create(seat, ws); |
| 503 | |
| 504 | return state; |
| 505 | } |
| 506 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 507 | static void |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 508 | restore_focus_state(struct desktop_shell *shell, struct workspace *ws) |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 509 | { |
| 510 | struct focus_state *state, *next; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 511 | struct weston_surface *surface; |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 512 | |
| 513 | wl_list_for_each_safe(state, next, &ws->focus_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 514 | surface = state->keyboard_focus; |
Jonas Ådahl | 5689944 | 2012-08-29 22:12:59 +0200 | [diff] [blame] | 515 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 516 | weston_keyboard_set_focus(state->seat->keyboard, surface); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | |
| 520 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 521 | replace_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 522 | struct weston_seat *seat) |
| 523 | { |
| 524 | struct focus_state *state; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 525 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 526 | |
| 527 | wl_list_for_each(state, &ws->focus_list, link) { |
| 528 | if (state->seat == seat) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 529 | surface = seat->keyboard->focus; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 530 | state->keyboard_focus = |
| 531 | (struct weston_surface *) surface; |
| 532 | return; |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | static void |
| 538 | drop_focus_state(struct desktop_shell *shell, struct workspace *ws, |
| 539 | struct weston_surface *surface) |
| 540 | { |
| 541 | struct focus_state *state; |
| 542 | |
| 543 | wl_list_for_each(state, &ws->focus_list, link) |
| 544 | if (state->keyboard_focus == surface) |
| 545 | state->keyboard_focus = NULL; |
| 546 | } |
| 547 | |
| 548 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 549 | workspace_destroy(struct workspace *ws) |
| 550 | { |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 551 | struct focus_state *state, *next; |
| 552 | |
| 553 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 554 | focus_state_destroy(state); |
| 555 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 556 | free(ws); |
| 557 | } |
| 558 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 559 | static void |
| 560 | seat_destroyed(struct wl_listener *listener, void *data) |
| 561 | { |
| 562 | struct weston_seat *seat = data; |
| 563 | struct focus_state *state, *next; |
| 564 | struct workspace *ws = container_of(listener, |
| 565 | struct workspace, |
| 566 | seat_destroyed_listener); |
| 567 | |
| 568 | wl_list_for_each_safe(state, next, &ws->focus_list, link) |
| 569 | if (state->seat == seat) |
| 570 | wl_list_remove(&state->link); |
| 571 | } |
| 572 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 573 | static struct workspace * |
| 574 | workspace_create(void) |
| 575 | { |
| 576 | struct workspace *ws = malloc(sizeof *ws); |
| 577 | if (ws == NULL) |
| 578 | return NULL; |
| 579 | |
| 580 | weston_layer_init(&ws->layer, NULL); |
| 581 | |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 582 | wl_list_init(&ws->focus_list); |
| 583 | wl_list_init(&ws->seat_destroyed_listener.link); |
| 584 | ws->seat_destroyed_listener.notify = seat_destroyed; |
| 585 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 586 | return ws; |
| 587 | } |
| 588 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 589 | static int |
| 590 | workspace_is_empty(struct workspace *ws) |
| 591 | { |
| 592 | return wl_list_empty(&ws->layer.surface_list); |
| 593 | } |
| 594 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 595 | static struct workspace * |
| 596 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 597 | { |
| 598 | struct workspace **pws = shell->workspaces.array.data; |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 599 | assert(index < shell->workspaces.num); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 600 | pws += index; |
| 601 | return *pws; |
| 602 | } |
| 603 | |
| 604 | static struct workspace * |
| 605 | get_current_workspace(struct desktop_shell *shell) |
| 606 | { |
| 607 | return get_workspace(shell, shell->workspaces.current); |
| 608 | } |
| 609 | |
| 610 | static void |
| 611 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 612 | { |
| 613 | struct workspace *ws; |
| 614 | |
| 615 | ws = get_workspace(shell, index); |
| 616 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 617 | |
| 618 | shell->workspaces.current = index; |
| 619 | } |
| 620 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 621 | static unsigned int |
| 622 | get_output_height(struct weston_output *output) |
| 623 | { |
| 624 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 625 | } |
| 626 | |
| 627 | static void |
| 628 | surface_translate(struct weston_surface *surface, double d) |
| 629 | { |
| 630 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 631 | struct weston_transform *transform; |
| 632 | |
| 633 | transform = &shsurf->workspace_transform; |
| 634 | if (wl_list_empty(&transform->link)) |
| 635 | wl_list_insert(surface->geometry.transformation_list.prev, |
| 636 | &shsurf->workspace_transform.link); |
| 637 | |
| 638 | weston_matrix_init(&shsurf->workspace_transform.matrix); |
| 639 | weston_matrix_translate(&shsurf->workspace_transform.matrix, |
| 640 | 0.0, d, 0.0); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 641 | weston_surface_geometry_dirty(surface); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | static void |
| 645 | workspace_translate_out(struct workspace *ws, double fraction) |
| 646 | { |
| 647 | struct weston_surface *surface; |
| 648 | unsigned int height; |
| 649 | double d; |
| 650 | |
| 651 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 652 | height = get_output_height(surface->output); |
| 653 | d = height * fraction; |
| 654 | |
| 655 | surface_translate(surface, d); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | static void |
| 660 | workspace_translate_in(struct workspace *ws, double fraction) |
| 661 | { |
| 662 | struct weston_surface *surface; |
| 663 | unsigned int height; |
| 664 | double d; |
| 665 | |
| 666 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 667 | height = get_output_height(surface->output); |
| 668 | |
| 669 | if (fraction > 0) |
| 670 | d = -(height - height * fraction); |
| 671 | else |
| 672 | d = height + height * fraction; |
| 673 | |
| 674 | surface_translate(surface, d); |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 679 | broadcast_current_workspace_state(struct desktop_shell *shell) |
| 680 | { |
| 681 | struct wl_resource *resource; |
| 682 | |
| 683 | wl_list_for_each(resource, &shell->workspaces.client_list, link) |
| 684 | workspace_manager_send_state(resource, |
| 685 | shell->workspaces.current, |
| 686 | shell->workspaces.num); |
| 687 | } |
| 688 | |
| 689 | static void |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 690 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 691 | unsigned int index, |
| 692 | struct workspace *from, |
| 693 | struct workspace *to) |
| 694 | { |
| 695 | shell->workspaces.current = index; |
| 696 | |
| 697 | shell->workspaces.anim_to = to; |
| 698 | shell->workspaces.anim_from = from; |
| 699 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 700 | shell->workspaces.anim_timestamp = 0; |
| 701 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 702 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | static void |
| 706 | workspace_deactivate_transforms(struct workspace *ws) |
| 707 | { |
| 708 | struct weston_surface *surface; |
| 709 | struct shell_surface *shsurf; |
| 710 | |
| 711 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 712 | shsurf = get_shell_surface(surface); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 713 | if (!wl_list_empty(&shsurf->workspace_transform.link)) { |
| 714 | wl_list_remove(&shsurf->workspace_transform.link); |
| 715 | wl_list_init(&shsurf->workspace_transform.link); |
| 716 | } |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 717 | weston_surface_geometry_dirty(surface); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | static void |
| 722 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 723 | struct workspace *from, |
| 724 | struct workspace *to) |
| 725 | { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 726 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 727 | |
| 728 | wl_list_remove(&shell->workspaces.animation.link); |
| 729 | workspace_deactivate_transforms(from); |
| 730 | workspace_deactivate_transforms(to); |
| 731 | shell->workspaces.anim_to = NULL; |
| 732 | |
| 733 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 734 | } |
| 735 | |
| 736 | static void |
| 737 | animate_workspace_change_frame(struct weston_animation *animation, |
| 738 | struct weston_output *output, uint32_t msecs) |
| 739 | { |
| 740 | struct desktop_shell *shell = |
| 741 | container_of(animation, struct desktop_shell, |
| 742 | workspaces.animation); |
| 743 | struct workspace *from = shell->workspaces.anim_from; |
| 744 | struct workspace *to = shell->workspaces.anim_to; |
| 745 | uint32_t t; |
| 746 | double x, y; |
| 747 | |
| 748 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 749 | finish_workspace_change_animation(shell, from, to); |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | if (shell->workspaces.anim_timestamp == 0) { |
| 754 | if (shell->workspaces.anim_current == 0.0) |
| 755 | shell->workspaces.anim_timestamp = msecs; |
| 756 | else |
| 757 | shell->workspaces.anim_timestamp = |
| 758 | msecs - |
| 759 | /* Invers of movement function 'y' below. */ |
| 760 | (asin(1.0 - shell->workspaces.anim_current) * |
| 761 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 762 | M_2_PI); |
| 763 | } |
| 764 | |
| 765 | t = msecs - shell->workspaces.anim_timestamp; |
| 766 | |
| 767 | /* |
| 768 | * x = [0, π/2] |
| 769 | * y(x) = sin(x) |
| 770 | */ |
| 771 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 772 | y = sin(x); |
| 773 | |
| 774 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 775 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 776 | |
| 777 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 778 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 779 | shell->workspaces.anim_current = y; |
| 780 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 781 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 782 | } |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 783 | else |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 784 | finish_workspace_change_animation(shell, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | static void |
| 788 | animate_workspace_change(struct desktop_shell *shell, |
| 789 | unsigned int index, |
| 790 | struct workspace *from, |
| 791 | struct workspace *to) |
| 792 | { |
| 793 | struct weston_output *output; |
| 794 | |
| 795 | int dir; |
| 796 | |
| 797 | if (index > shell->workspaces.current) |
| 798 | dir = -1; |
| 799 | else |
| 800 | dir = 1; |
| 801 | |
| 802 | shell->workspaces.current = index; |
| 803 | |
| 804 | shell->workspaces.anim_dir = dir; |
| 805 | shell->workspaces.anim_from = from; |
| 806 | shell->workspaces.anim_to = to; |
| 807 | shell->workspaces.anim_current = 0.0; |
| 808 | shell->workspaces.anim_timestamp = 0; |
| 809 | |
| 810 | output = container_of(shell->compositor->output_list.next, |
| 811 | struct weston_output, link); |
| 812 | wl_list_insert(&output->animation_list, |
| 813 | &shell->workspaces.animation.link); |
| 814 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 815 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 816 | |
| 817 | workspace_translate_in(to, 0); |
| 818 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 819 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 820 | |
Scott Moreau | 4272e63 | 2012-08-13 09:58:41 -0600 | [diff] [blame] | 821 | weston_compositor_schedule_repaint(shell->compositor); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 822 | } |
| 823 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 824 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 825 | update_workspace(struct desktop_shell *shell, unsigned int index, |
| 826 | struct workspace *from, struct workspace *to) |
| 827 | { |
| 828 | shell->workspaces.current = index; |
| 829 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 830 | wl_list_remove(&from->layer.link); |
| 831 | } |
| 832 | |
| 833 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 834 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 835 | { |
| 836 | struct workspace *from; |
| 837 | struct workspace *to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 838 | |
| 839 | if (index == shell->workspaces.current) |
| 840 | return; |
| 841 | |
| 842 | /* Don't change workspace when there is any fullscreen surfaces. */ |
| 843 | if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 844 | return; |
| 845 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 846 | from = get_current_workspace(shell); |
| 847 | to = get_workspace(shell, index); |
| 848 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 849 | if (shell->workspaces.anim_from == to && |
| 850 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 851 | restore_focus_state(shell, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 852 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 853 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 854 | return; |
| 855 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 856 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 857 | if (shell->workspaces.anim_to != NULL) |
| 858 | finish_workspace_change_animation(shell, |
| 859 | shell->workspaces.anim_from, |
| 860 | shell->workspaces.anim_to); |
| 861 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 862 | restore_focus_state(shell, to); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 863 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 864 | if (workspace_is_empty(to) && workspace_is_empty(from)) |
| 865 | update_workspace(shell, index, from, to); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 866 | else |
| 867 | animate_workspace_change(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 868 | |
| 869 | broadcast_current_workspace_state(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 870 | } |
| 871 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 872 | static bool |
| 873 | workspace_has_only(struct workspace *ws, struct weston_surface *surface) |
| 874 | { |
| 875 | struct wl_list *list = &ws->layer.surface_list; |
| 876 | struct wl_list *e; |
| 877 | |
| 878 | if (wl_list_empty(list)) |
| 879 | return false; |
| 880 | |
| 881 | e = list->next; |
| 882 | |
| 883 | if (e->next != list) |
| 884 | return false; |
| 885 | |
| 886 | return container_of(e, struct weston_surface, layer_link) == surface; |
| 887 | } |
| 888 | |
| 889 | static void |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 890 | move_surface_to_workspace(struct desktop_shell *shell, |
| 891 | struct weston_surface *surface, |
| 892 | uint32_t workspace) |
| 893 | { |
| 894 | struct workspace *from; |
| 895 | struct workspace *to; |
| 896 | struct weston_seat *seat; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 897 | struct weston_surface *focus; |
| 898 | |
| 899 | assert(weston_surface_get_main_surface(surface) == surface); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 900 | |
| 901 | if (workspace == shell->workspaces.current) |
| 902 | return; |
| 903 | |
Philipp Brüschweiler | 067abf6 | 2012-09-01 16:03:05 +0200 | [diff] [blame] | 904 | if (workspace >= shell->workspaces.num) |
| 905 | workspace = shell->workspaces.num - 1; |
| 906 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 907 | from = get_current_workspace(shell); |
| 908 | to = get_workspace(shell, workspace); |
| 909 | |
| 910 | wl_list_remove(&surface->layer_link); |
| 911 | wl_list_insert(&to->layer.surface_list, &surface->layer_link); |
| 912 | |
| 913 | drop_focus_state(shell, from, surface); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 914 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 915 | if (!seat->keyboard) |
| 916 | continue; |
| 917 | |
| 918 | focus = weston_surface_get_main_surface(seat->keyboard->focus); |
| 919 | if (focus == surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 920 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 921 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 922 | |
| 923 | weston_surface_damage_below(surface); |
| 924 | } |
| 925 | |
| 926 | static void |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 927 | take_surface_to_workspace_by_seat(struct desktop_shell *shell, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 928 | struct weston_seat *seat, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 929 | unsigned int index) |
| 930 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 931 | struct weston_surface *surface; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 932 | struct shell_surface *shsurf; |
| 933 | struct workspace *from; |
| 934 | struct workspace *to; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 935 | struct focus_state *state; |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 936 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 937 | surface = weston_surface_get_main_surface(seat->keyboard->focus); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 938 | if (surface == NULL || |
| 939 | index == shell->workspaces.current) |
| 940 | return; |
| 941 | |
| 942 | from = get_current_workspace(shell); |
| 943 | to = get_workspace(shell, index); |
| 944 | |
| 945 | wl_list_remove(&surface->layer_link); |
| 946 | wl_list_insert(&to->layer.surface_list, &surface->layer_link); |
| 947 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 948 | replace_focus_state(shell, to, seat); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 949 | drop_focus_state(shell, from, surface); |
| 950 | |
| 951 | if (shell->workspaces.anim_from == to && |
| 952 | shell->workspaces.anim_to == from) { |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 953 | wl_list_remove(&to->layer.link); |
| 954 | wl_list_insert(from->layer.link.prev, &to->layer.link); |
| 955 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 956 | reverse_workspace_change_animation(shell, index, from, to); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 957 | broadcast_current_workspace_state(shell); |
| 958 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 959 | return; |
| 960 | } |
| 961 | |
| 962 | if (shell->workspaces.anim_to != NULL) |
| 963 | finish_workspace_change_animation(shell, |
| 964 | shell->workspaces.anim_from, |
| 965 | shell->workspaces.anim_to); |
| 966 | |
| 967 | if (workspace_is_empty(from) && |
| 968 | workspace_has_only(to, surface)) |
| 969 | update_workspace(shell, index, from, to); |
| 970 | else { |
| 971 | shsurf = get_shell_surface(surface); |
| 972 | if (wl_list_empty(&shsurf->workspace_transform.link)) |
| 973 | wl_list_insert(&shell->workspaces.anim_sticky_list, |
| 974 | &shsurf->workspace_transform.link); |
| 975 | |
| 976 | animate_workspace_change(shell, index, from, to); |
| 977 | } |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 978 | |
| 979 | broadcast_current_workspace_state(shell); |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 980 | |
| 981 | state = ensure_focus_state(shell, seat); |
| 982 | if (state != NULL) |
| 983 | state->keyboard_focus = surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | static void |
| 987 | workspace_manager_move_surface(struct wl_client *client, |
| 988 | struct wl_resource *resource, |
| 989 | struct wl_resource *surface_resource, |
| 990 | uint32_t workspace) |
| 991 | { |
| 992 | struct desktop_shell *shell = resource->data; |
| 993 | struct weston_surface *surface = |
| 994 | (struct weston_surface *) surface_resource; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 995 | struct weston_surface *main_surface; |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 996 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 997 | main_surface = weston_surface_get_main_surface(surface); |
| 998 | move_surface_to_workspace(shell, main_surface, workspace); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static const struct workspace_manager_interface workspace_manager_implementation = { |
| 1002 | workspace_manager_move_surface, |
| 1003 | }; |
| 1004 | |
| 1005 | static void |
| 1006 | unbind_resource(struct wl_resource *resource) |
| 1007 | { |
| 1008 | wl_list_remove(&resource->link); |
| 1009 | free(resource); |
| 1010 | } |
| 1011 | |
| 1012 | static void |
| 1013 | bind_workspace_manager(struct wl_client *client, |
| 1014 | void *data, uint32_t version, uint32_t id) |
| 1015 | { |
| 1016 | struct desktop_shell *shell = data; |
| 1017 | struct wl_resource *resource; |
| 1018 | |
| 1019 | resource = wl_client_add_object(client, &workspace_manager_interface, |
| 1020 | &workspace_manager_implementation, |
| 1021 | id, shell); |
| 1022 | |
| 1023 | if (resource == NULL) { |
| 1024 | weston_log("couldn't add workspace manager object"); |
| 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | resource->destroy = unbind_resource; |
| 1029 | wl_list_insert(&shell->workspaces.client_list, &resource->link); |
| 1030 | |
| 1031 | workspace_manager_send_state(resource, |
| 1032 | shell->workspaces.current, |
| 1033 | shell->workspaces.num); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 1036 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1037 | noop_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1038 | { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | static void |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 1042 | move_grab_motion(struct weston_pointer_grab *grab, uint32_t time) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1043 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1044 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1045 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1046 | struct shell_surface *shsurf = move->base.shsurf; |
| 1047 | struct weston_surface *es; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1048 | int dx = wl_fixed_to_int(pointer->x + move->dx); |
| 1049 | int dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1050 | |
| 1051 | if (!shsurf) |
| 1052 | return; |
| 1053 | |
| 1054 | es = shsurf->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1055 | |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1056 | weston_surface_configure(es, dx, dy, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1057 | es->geometry.width, es->geometry.height); |
Kristian Høgsberg | 6c6fb99 | 2012-06-21 12:06:22 -0400 | [diff] [blame] | 1058 | |
| 1059 | weston_compositor_schedule_repaint(es->compositor); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1063 | move_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1064 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1065 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1066 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 1067 | grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1068 | struct weston_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1069 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1070 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1071 | if (pointer->button_count == 0 && |
| 1072 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1073 | shell_grab_end(shell_grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1074 | free(grab); |
| 1075 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1076 | } |
| 1077 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1078 | static const struct weston_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1079 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1080 | move_grab_motion, |
| 1081 | move_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1082 | }; |
| 1083 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1084 | static int |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1085 | surface_move(struct shell_surface *shsurf, struct weston_seat *seat) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1086 | { |
| 1087 | struct weston_move_grab *move; |
| 1088 | |
| 1089 | if (!shsurf) |
| 1090 | return -1; |
| 1091 | |
| 1092 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1093 | return 0; |
| 1094 | |
| 1095 | move = malloc(sizeof *move); |
| 1096 | if (!move) |
| 1097 | return -1; |
| 1098 | |
| 1099 | move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1100 | seat->pointer->grab_x; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1101 | move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) - |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1102 | seat->pointer->grab_y; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1103 | |
| 1104 | shell_grab_start(&move->base, &move_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1105 | seat->pointer, DESKTOP_SHELL_CURSOR_MOVE); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1106 | |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | static void |
| 1111 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 1112 | struct wl_resource *seat_resource, uint32_t serial) |
| 1113 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1114 | struct weston_seat *seat = seat_resource->data; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1115 | struct shell_surface *shsurf = resource->data; |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1116 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1117 | |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1118 | surface = weston_surface_get_main_surface(seat->pointer->focus); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1119 | if (seat->pointer->button_count == 0 || |
| 1120 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1121 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1122 | return; |
| 1123 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1124 | if (surface_move(shsurf, seat) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1125 | wl_resource_post_no_memory(resource); |
| 1126 | } |
| 1127 | |
| 1128 | struct weston_resize_grab { |
| 1129 | struct shell_grab base; |
| 1130 | uint32_t edges; |
| 1131 | int32_t width, height; |
| 1132 | }; |
| 1133 | |
| 1134 | static void |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 1135 | resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1136 | { |
| 1137 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1138 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1139 | struct shell_surface *shsurf = resize->base.shsurf; |
| 1140 | int32_t width, height; |
| 1141 | wl_fixed_t from_x, from_y; |
| 1142 | wl_fixed_t to_x, to_y; |
| 1143 | |
| 1144 | if (!shsurf) |
| 1145 | return; |
| 1146 | |
| 1147 | weston_surface_from_global_fixed(shsurf->surface, |
| 1148 | pointer->grab_x, pointer->grab_y, |
| 1149 | &from_x, &from_y); |
| 1150 | weston_surface_from_global_fixed(shsurf->surface, |
| 1151 | pointer->x, pointer->y, &to_x, &to_y); |
| 1152 | |
| 1153 | width = resize->width; |
| 1154 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
| 1155 | width += wl_fixed_to_int(from_x - to_x); |
| 1156 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
| 1157 | width += wl_fixed_to_int(to_x - from_x); |
| 1158 | } |
| 1159 | |
| 1160 | height = resize->height; |
| 1161 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
| 1162 | height += wl_fixed_to_int(from_y - to_y); |
| 1163 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
| 1164 | height += wl_fixed_to_int(to_y - from_y); |
| 1165 | } |
| 1166 | |
| 1167 | shsurf->client->send_configure(shsurf->surface, |
| 1168 | resize->edges, width, height); |
| 1169 | } |
| 1170 | |
| 1171 | static void |
| 1172 | send_configure(struct weston_surface *surface, |
| 1173 | uint32_t edges, int32_t width, int32_t height) |
| 1174 | { |
| 1175 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 1176 | |
| 1177 | wl_shell_surface_send_configure(&shsurf->resource, |
| 1178 | edges, width, height); |
| 1179 | } |
| 1180 | |
| 1181 | static const struct weston_shell_client shell_client = { |
| 1182 | send_configure |
| 1183 | }; |
| 1184 | |
| 1185 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1186 | resize_grab_button(struct weston_pointer_grab *grab, |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1187 | uint32_t time, uint32_t button, uint32_t state_w) |
| 1188 | { |
| 1189 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1190 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1191 | enum wl_pointer_button_state state = state_w; |
| 1192 | |
| 1193 | if (pointer->button_count == 0 && |
| 1194 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
| 1195 | shell_grab_end(&resize->base); |
| 1196 | free(grab); |
| 1197 | } |
| 1198 | } |
| 1199 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1200 | static const struct weston_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1201 | noop_grab_focus, |
| 1202 | resize_grab_motion, |
| 1203 | resize_grab_button, |
| 1204 | }; |
| 1205 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1206 | /* |
| 1207 | * Returns the bounding box of a surface and all its sub-surfaces, |
| 1208 | * in the surface coordinates system. */ |
| 1209 | static void |
| 1210 | surface_subsurfaces_boundingbox(struct weston_surface *surface, int32_t *x, |
| 1211 | int32_t *y, int32_t *w, int32_t *h) { |
| 1212 | pixman_region32_t region; |
| 1213 | pixman_box32_t *box; |
| 1214 | struct weston_subsurface *subsurface; |
| 1215 | |
| 1216 | pixman_region32_init_rect(®ion, 0, 0, |
| 1217 | surface->geometry.width, |
| 1218 | surface->geometry.height); |
| 1219 | |
| 1220 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { |
| 1221 | pixman_region32_union_rect(®ion, ®ion, |
| 1222 | subsurface->position.x, |
| 1223 | subsurface->position.y, |
| 1224 | subsurface->surface->geometry.width, |
| 1225 | subsurface->surface->geometry.height); |
| 1226 | } |
| 1227 | |
| 1228 | box = pixman_region32_extents(®ion); |
| 1229 | if (x) |
| 1230 | *x = box->x1; |
| 1231 | if (y) |
| 1232 | *y = box->y1; |
| 1233 | if (w) |
| 1234 | *w = box->x2 - box->x1; |
| 1235 | if (h) |
| 1236 | *h = box->y2 - box->y1; |
| 1237 | |
| 1238 | pixman_region32_fini(®ion); |
| 1239 | } |
| 1240 | |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1241 | static int |
| 1242 | surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1243 | struct weston_seat *seat, uint32_t edges) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1244 | { |
| 1245 | struct weston_resize_grab *resize; |
| 1246 | |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 1247 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 1248 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1249 | return 0; |
| 1250 | |
| 1251 | if (edges == 0 || edges > 15 || |
| 1252 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1253 | return 0; |
| 1254 | |
| 1255 | resize = malloc(sizeof *resize); |
| 1256 | if (!resize) |
| 1257 | return -1; |
| 1258 | |
| 1259 | resize->edges = edges; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1260 | surface_subsurfaces_boundingbox(shsurf->surface, NULL, NULL, |
| 1261 | &resize->width, &resize->height); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1262 | |
| 1263 | shell_grab_start(&resize->base, &resize_grab_interface, shsurf, |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1264 | seat->pointer, edges); |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1265 | |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | static void |
| 1270 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 1271 | struct wl_resource *seat_resource, uint32_t serial, |
| 1272 | uint32_t edges) |
| 1273 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1274 | struct weston_seat *seat = seat_resource->data; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1275 | struct shell_surface *shsurf = resource->data; |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1276 | struct weston_surface *surface; |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1277 | |
| 1278 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1279 | return; |
| 1280 | |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1281 | surface = weston_surface_get_main_surface(seat->pointer->focus); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1282 | if (seat->pointer->button_count == 0 || |
| 1283 | seat->pointer->grab_serial != serial || |
Giulio Camuffo | 61da3fc | 2013-04-25 13:57:45 +0300 | [diff] [blame] | 1284 | surface != shsurf->surface) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1285 | return; |
| 1286 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1287 | if (surface_resize(shsurf, seat, edges) < 0) |
Kristian Høgsberg | 9e31bff | 2012-08-01 00:08:07 -0400 | [diff] [blame] | 1288 | wl_resource_post_no_memory(resource); |
| 1289 | } |
| 1290 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1291 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1292 | busy_cursor_grab_focus(struct weston_pointer_grab *base) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1293 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1294 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1295 | struct weston_pointer *pointer = base->pointer; |
| 1296 | struct weston_surface *surface; |
| 1297 | wl_fixed_t sx, sy; |
| 1298 | |
| 1299 | surface = weston_compositor_pick_surface(pointer->seat->compositor, |
| 1300 | pointer->x, pointer->y, |
| 1301 | &sx, &sy); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1302 | |
Rob Bradford | 2f8d9aa | 2013-05-20 12:09:20 +0100 | [diff] [blame] | 1303 | if (!grab->shsurf || grab->shsurf->surface != surface) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1304 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1305 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | static void |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 1310 | busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1311 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1312 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1313 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1314 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1315 | busy_cursor_grab_button(struct weston_pointer_grab *base, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1316 | uint32_t time, uint32_t button, uint32_t state) |
| 1317 | { |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1318 | struct shell_grab *grab = (struct shell_grab *) base; |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1319 | struct shell_surface *shsurf = grab->shsurf; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1320 | struct weston_seat *seat = grab->grab.pointer->seat; |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1321 | |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1322 | if (shsurf && button == BTN_LEFT && state) { |
| 1323 | activate(shsurf->shell, shsurf->surface, seat); |
| 1324 | surface_move(shsurf, seat); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 1325 | } else if (shsurf && button == BTN_RIGHT && state) { |
| 1326 | activate(shsurf->shell, shsurf->surface, seat); |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1327 | surface_rotate(shsurf, seat); |
Kristian Høgsberg | bbe9839 | 2012-08-01 00:20:21 -0400 | [diff] [blame] | 1328 | } |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1329 | } |
| 1330 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1331 | static const struct weston_pointer_grab_interface busy_cursor_grab_interface = { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1332 | busy_cursor_grab_focus, |
| 1333 | busy_cursor_grab_motion, |
| 1334 | busy_cursor_grab_button, |
| 1335 | }; |
| 1336 | |
| 1337 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1338 | set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1339 | { |
| 1340 | struct shell_grab *grab; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1341 | |
| 1342 | grab = malloc(sizeof *grab); |
| 1343 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1344 | return; |
| 1345 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1346 | shell_grab_start(grab, &busy_cursor_grab_interface, shsurf, pointer, |
| 1347 | DESKTOP_SHELL_CURSOR_BUSY); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1348 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1349 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1350 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1351 | end_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer) |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1352 | { |
| 1353 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 1354 | |
Kristian Høgsberg | e122b7b | 2013-05-08 16:47:00 -0400 | [diff] [blame] | 1355 | if (grab->grab.interface == &busy_cursor_grab_interface && |
| 1356 | grab->shsurf == shsurf) { |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 1357 | shell_grab_end(grab); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1358 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1359 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1360 | } |
| 1361 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1362 | static void |
| 1363 | ping_timer_destroy(struct shell_surface *shsurf) |
| 1364 | { |
| 1365 | if (!shsurf || !shsurf->ping_timer) |
| 1366 | return; |
| 1367 | |
| 1368 | if (shsurf->ping_timer->source) |
| 1369 | wl_event_source_remove(shsurf->ping_timer->source); |
| 1370 | |
| 1371 | free(shsurf->ping_timer); |
| 1372 | shsurf->ping_timer = NULL; |
| 1373 | } |
| 1374 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1375 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1376 | ping_timeout_handler(void *data) |
| 1377 | { |
| 1378 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1379 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1380 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1381 | /* Client is not responding */ |
| 1382 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1383 | |
| 1384 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 1385 | if (seat->pointer->focus == shsurf->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1386 | set_busy_cursor(shsurf, seat->pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1387 | |
| 1388 | return 1; |
| 1389 | } |
| 1390 | |
| 1391 | static void |
| 1392 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 1393 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 1394 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1395 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1396 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1397 | |
| 1398 | if (!shsurf) |
| 1399 | return; |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 1400 | if (!shsurf->resource.client) |
| 1401 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1402 | |
Ander Conselvan de Oliveira | eac9a46 | 2012-07-16 14:15:48 +0300 | [diff] [blame] | 1403 | if (shsurf->surface == shsurf->shell->grab_surface) |
| 1404 | return; |
| 1405 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1406 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 1407 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1408 | if (!shsurf->ping_timer) |
| 1409 | return; |
| 1410 | |
| 1411 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1412 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 1413 | shsurf->ping_timer->source = |
| 1414 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 1415 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 1416 | |
| 1417 | wl_shell_surface_send_ping(&shsurf->resource, serial); |
| 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1422 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 1423 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1424 | struct weston_pointer *pointer = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1425 | struct weston_surface *surface = |
| 1426 | (struct weston_surface *) pointer->focus; |
| 1427 | struct weston_compositor *compositor; |
| 1428 | struct shell_surface *shsurf; |
| 1429 | uint32_t serial; |
| 1430 | |
| 1431 | if (!surface) |
| 1432 | return; |
| 1433 | |
| 1434 | compositor = surface->compositor; |
| 1435 | shsurf = get_shell_surface(surface); |
| 1436 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 1437 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1438 | set_busy_cursor(shsurf, pointer); |
| 1439 | } else { |
| 1440 | serial = wl_display_next_serial(compositor->wl_display); |
| 1441 | ping_handler(surface, serial); |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | static void |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1446 | create_pointer_focus_listener(struct weston_seat *seat) |
| 1447 | { |
| 1448 | struct wl_listener *listener; |
| 1449 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1450 | if (!seat->pointer) |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1451 | return; |
| 1452 | |
| 1453 | listener = malloc(sizeof *listener); |
| 1454 | listener->notify = handle_pointer_focus; |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1455 | wl_signal_add(&seat->pointer->focus_signal, listener); |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1459 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 1460 | uint32_t serial) |
| 1461 | { |
| 1462 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1463 | struct weston_seat *seat; |
| 1464 | struct weston_compositor *ec = shsurf->surface->compositor; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1465 | |
Kristian Høgsberg | 92374e1 | 2012-08-11 22:39:12 -0400 | [diff] [blame] | 1466 | if (shsurf->ping_timer == NULL) |
| 1467 | /* Just ignore unsolicited pong. */ |
| 1468 | return; |
| 1469 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1470 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1471 | shsurf->unresponsive = 0; |
Hardening | eb1e130 | 2013-05-17 18:07:41 +0200 | [diff] [blame] | 1472 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 1473 | if(seat->pointer) |
| 1474 | end_busy_cursor(shsurf, seat->pointer); |
| 1475 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1476 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1477 | } |
| 1478 | } |
| 1479 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1480 | static void |
| 1481 | shell_surface_set_title(struct wl_client *client, |
| 1482 | struct wl_resource *resource, const char *title) |
| 1483 | { |
| 1484 | struct shell_surface *shsurf = resource->data; |
| 1485 | |
| 1486 | free(shsurf->title); |
| 1487 | shsurf->title = strdup(title); |
| 1488 | } |
| 1489 | |
| 1490 | static void |
| 1491 | shell_surface_set_class(struct wl_client *client, |
| 1492 | struct wl_resource *resource, const char *class) |
| 1493 | { |
| 1494 | struct shell_surface *shsurf = resource->data; |
| 1495 | |
| 1496 | free(shsurf->class); |
| 1497 | shsurf->class = strdup(class); |
| 1498 | } |
| 1499 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1500 | static struct weston_output * |
| 1501 | get_default_output(struct weston_compositor *compositor) |
| 1502 | { |
| 1503 | return container_of(compositor->output_list.next, |
| 1504 | struct weston_output, link); |
| 1505 | } |
| 1506 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1507 | static void |
| 1508 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 1509 | { |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 1510 | struct workspace *ws; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1511 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1512 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1513 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1514 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1515 | shsurf->fullscreen_output->origin); |
| 1516 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1517 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 1518 | shsurf->fullscreen.framerate = 0; |
| 1519 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 1520 | wl_list_init(&shsurf->fullscreen.transform.link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1521 | if (shsurf->fullscreen.black_surface) |
| 1522 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1523 | shsurf->fullscreen.black_surface = NULL; |
| 1524 | shsurf->fullscreen_output = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1525 | weston_surface_set_position(shsurf->surface, |
| 1526 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1527 | if (shsurf->saved_rotation_valid) { |
| 1528 | wl_list_insert(&shsurf->surface->geometry.transformation_list, |
| 1529 | &shsurf->rotation.transform.link); |
| 1530 | shsurf->saved_rotation_valid = false; |
| 1531 | } |
Rafal Mielniczuk | 3e3862c | 2012-10-07 20:25:36 +0200 | [diff] [blame] | 1532 | |
| 1533 | ws = get_current_workspace(shsurf->shell); |
| 1534 | wl_list_remove(&shsurf->surface->layer_link); |
| 1535 | wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1536 | } |
| 1537 | |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1538 | static void |
| 1539 | shell_unset_maximized(struct shell_surface *shsurf) |
| 1540 | { |
| 1541 | struct workspace *ws; |
| 1542 | /* undo all maximized things here */ |
| 1543 | shsurf->output = get_default_output(shsurf->surface->compositor); |
| 1544 | weston_surface_set_position(shsurf->surface, |
| 1545 | shsurf->saved_x, |
| 1546 | shsurf->saved_y); |
| 1547 | |
| 1548 | if (shsurf->saved_rotation_valid) { |
| 1549 | wl_list_insert(&shsurf->surface->geometry.transformation_list, |
| 1550 | &shsurf->rotation.transform.link); |
| 1551 | shsurf->saved_rotation_valid = false; |
| 1552 | } |
| 1553 | |
| 1554 | ws = get_current_workspace(shsurf->shell); |
| 1555 | wl_list_remove(&shsurf->surface->layer_link); |
| 1556 | wl_list_insert(&ws->layer.surface_list, &shsurf->surface->layer_link); |
| 1557 | } |
| 1558 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1559 | static int |
| 1560 | reset_shell_surface_type(struct shell_surface *surface) |
| 1561 | { |
| 1562 | switch (surface->type) { |
| 1563 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1564 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1565 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1566 | case SHELL_SURFACE_MAXIMIZED: |
Rafal Mielniczuk | fffdcdd | 2013-03-11 19:26:54 +0100 | [diff] [blame] | 1567 | shell_unset_maximized(surface); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1568 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1569 | case SHELL_SURFACE_NONE: |
| 1570 | case SHELL_SURFACE_TOPLEVEL: |
| 1571 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1572 | case SHELL_SURFACE_POPUP: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1573 | break; |
| 1574 | } |
| 1575 | |
| 1576 | surface->type = SHELL_SURFACE_NONE; |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1580 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1581 | set_surface_type(struct shell_surface *shsurf) |
| 1582 | { |
| 1583 | struct weston_surface *surface = shsurf->surface; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1584 | struct weston_surface *pes = shsurf->parent; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1585 | |
| 1586 | reset_shell_surface_type(shsurf); |
| 1587 | |
| 1588 | shsurf->type = shsurf->next_type; |
| 1589 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 1590 | |
| 1591 | switch (shsurf->type) { |
| 1592 | case SHELL_SURFACE_TOPLEVEL: |
| 1593 | break; |
| 1594 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1595 | weston_surface_set_position(surface, |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 1596 | pes->geometry.x + shsurf->transient.x, |
| 1597 | pes->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1598 | break; |
| 1599 | |
| 1600 | case SHELL_SURFACE_MAXIMIZED: |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1601 | case SHELL_SURFACE_FULLSCREEN: |
| 1602 | shsurf->saved_x = surface->geometry.x; |
| 1603 | shsurf->saved_y = surface->geometry.y; |
| 1604 | shsurf->saved_position_valid = true; |
| 1605 | |
| 1606 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 1607 | wl_list_remove(&shsurf->rotation.transform.link); |
| 1608 | wl_list_init(&shsurf->rotation.transform.link); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1609 | weston_surface_geometry_dirty(shsurf->surface); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1610 | shsurf->saved_rotation_valid = true; |
| 1611 | } |
| 1612 | break; |
| 1613 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1614 | default: |
| 1615 | break; |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1620 | set_toplevel(struct shell_surface *shsurf) |
| 1621 | { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1622 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1626 | shell_surface_set_toplevel(struct wl_client *client, |
| 1627 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1628 | { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1629 | struct shell_surface *surface = resource->data; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1630 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1631 | set_toplevel(surface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | static void |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1635 | set_transient(struct shell_surface *shsurf, |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1636 | struct weston_surface *parent, int x, int y, uint32_t flags) |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1637 | { |
| 1638 | /* assign to parents output */ |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1639 | shsurf->parent = parent; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1640 | shsurf->transient.x = x; |
| 1641 | shsurf->transient.y = y; |
| 1642 | shsurf->transient.flags = flags; |
| 1643 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 1644 | } |
| 1645 | |
| 1646 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1647 | shell_surface_set_transient(struct wl_client *client, |
| 1648 | struct wl_resource *resource, |
| 1649 | struct wl_resource *parent_resource, |
| 1650 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1651 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1652 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1653 | struct weston_surface *parent = parent_resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1654 | |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1655 | set_transient(shsurf, parent, x, y, flags); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1656 | } |
| 1657 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1658 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1659 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1660 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1661 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1665 | get_output_panel_height(struct desktop_shell *shell, |
| 1666 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1667 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1668 | struct weston_surface *surface; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1669 | int panel_height = 0; |
| 1670 | |
| 1671 | if (!output) |
| 1672 | return 0; |
| 1673 | |
Juan Zhao | 4ab9468 | 2012-07-09 22:24:09 -0700 | [diff] [blame] | 1674 | wl_list_for_each(surface, &shell->panel_layer.surface_list, layer_link) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1675 | if (surface->output == output) { |
| 1676 | panel_height = surface->geometry.height; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1677 | break; |
| 1678 | } |
| 1679 | } |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1680 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1681 | return panel_height; |
| 1682 | } |
| 1683 | |
| 1684 | static void |
| 1685 | shell_surface_set_maximized(struct wl_client *client, |
| 1686 | struct wl_resource *resource, |
| 1687 | struct wl_resource *output_resource ) |
| 1688 | { |
| 1689 | struct shell_surface *shsurf = resource->data; |
| 1690 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1691 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1692 | uint32_t edges = 0, panel_height = 0; |
| 1693 | |
| 1694 | /* get the default output, if the client set it as NULL |
| 1695 | check whether the ouput is available */ |
| 1696 | if (output_resource) |
| 1697 | shsurf->output = output_resource->data; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 1698 | else if (es->output) |
| 1699 | shsurf->output = es->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1700 | else |
| 1701 | shsurf->output = get_default_output(es->compositor); |
| 1702 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1703 | shell = shell_surface_get_shell(shsurf); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 1704 | panel_height = get_output_panel_height(shell, shsurf->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1705 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1706 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1707 | shsurf->client->send_configure(shsurf->surface, edges, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1708 | shsurf->output->width, |
| 1709 | shsurf->output->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1710 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1711 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1714 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1715 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height); |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1716 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1717 | static struct weston_surface * |
| 1718 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1719 | struct weston_surface *fs_surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1720 | float x, float y, int w, int h) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1721 | { |
| 1722 | struct weston_surface *surface = NULL; |
| 1723 | |
| 1724 | surface = weston_surface_create(ec); |
| 1725 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1726 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1727 | return NULL; |
| 1728 | } |
| 1729 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1730 | surface->configure = black_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 1731 | surface->configure_private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1732 | weston_surface_configure(surface, x, y, w, h); |
| 1733 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
Pekka Paalanen | 71f6f3b | 2012-10-10 12:49:26 +0300 | [diff] [blame] | 1734 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 1735 | pixman_region32_init_rect(&surface->opaque, 0, 0, w, h); |
Jonas Ådahl | 33619a4 | 2013-01-15 21:25:55 +0100 | [diff] [blame] | 1736 | pixman_region32_fini(&surface->input); |
| 1737 | pixman_region32_init_rect(&surface->input, 0, 0, w, h); |
Kristian Høgsberg | 61f00f5 | 2012-08-03 16:31:36 -0400 | [diff] [blame] | 1738 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1739 | return surface; |
| 1740 | } |
| 1741 | |
| 1742 | /* Create black surface and append it to the associated fullscreen surface. |
| 1743 | * Handle size dismatch and positioning according to the method. */ |
| 1744 | static void |
| 1745 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 1746 | { |
| 1747 | struct weston_output *output = shsurf->fullscreen_output; |
| 1748 | struct weston_surface *surface = shsurf->surface; |
| 1749 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1750 | float scale, output_aspect, surface_aspect, x, y; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1751 | int32_t surf_x, surf_y, surf_width, surf_height; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1752 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1753 | if (!shsurf->fullscreen.black_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1754 | shsurf->fullscreen.black_surface = |
| 1755 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1756 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1757 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1758 | output->width, |
| 1759 | output->height); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1760 | |
| 1761 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
| 1762 | wl_list_insert(&surface->layer_link, |
| 1763 | &shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1764 | shsurf->fullscreen.black_surface->output = output; |
| 1765 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1766 | surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, |
| 1767 | &surf_width, &surf_height); |
| 1768 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1769 | switch (shsurf->fullscreen.type) { |
| 1770 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1771 | if (surface->buffer_ref.buffer) |
Kristian Høgsberg | a08b528 | 2012-07-20 15:30:36 -0400 | [diff] [blame] | 1772 | center_on_output(surface, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1773 | break; |
| 1774 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 1775 | /* 1:1 mapping between surface and output dimensions */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1776 | if (output->width == surf_width && |
| 1777 | output->height == surf_height) { |
| 1778 | weston_surface_set_position(surface, output->x - surf_x, |
| 1779 | output->y - surf_y); |
Rob Bradford | 9f3dd15 | 2013-02-12 11:53:47 +0000 | [diff] [blame] | 1780 | break; |
| 1781 | } |
| 1782 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1783 | matrix = &shsurf->fullscreen.transform.matrix; |
| 1784 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1785 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1786 | output_aspect = (float) output->width / |
| 1787 | (float) output->height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1788 | surface_aspect = (float) surface->geometry.width / |
| 1789 | (float) surface->geometry.height; |
| 1790 | if (output_aspect < surface_aspect) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1791 | scale = (float) output->width / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1792 | (float) surf_width; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1793 | else |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1794 | scale = (float) output->height / |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1795 | (float) surf_height; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1796 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1797 | weston_matrix_scale(matrix, scale, scale, 1); |
| 1798 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1799 | wl_list_insert(&surface->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1800 | &shsurf->fullscreen.transform.link); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1801 | x = output->x + (output->width - surf_width * scale) / 2 - surf_x; |
| 1802 | y = output->y + (output->height - surf_height * scale) / 2 - surf_y; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1803 | weston_surface_set_position(surface, x, y); |
| 1804 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1805 | break; |
| 1806 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1807 | if (shell_surface_is_top_fullscreen(shsurf)) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 1808 | struct weston_mode mode = {0, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1809 | surf_width, |
| 1810 | surf_height, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1811 | shsurf->fullscreen.framerate}; |
| 1812 | |
| 1813 | if (weston_output_switch_mode(output, &mode) == 0) { |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 1814 | weston_surface_configure(shsurf->fullscreen.black_surface, |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 1815 | output->x - surf_x, |
| 1816 | output->y - surf_y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1817 | output->width, |
| 1818 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1819 | break; |
| 1820 | } |
| 1821 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1822 | break; |
| 1823 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
| 1824 | break; |
| 1825 | default: |
| 1826 | break; |
| 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | /* make the fullscreen and black surface at the top */ |
| 1831 | static void |
| 1832 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 1833 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1834 | struct weston_output *output = shsurf->fullscreen_output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1835 | struct weston_surface *surface = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1836 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1837 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1838 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1839 | wl_list_insert(&shell->fullscreen_layer.surface_list, |
| 1840 | &surface->layer_link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1841 | weston_surface_damage(surface); |
| 1842 | |
| 1843 | if (!shsurf->fullscreen.black_surface) |
| 1844 | shsurf->fullscreen.black_surface = |
| 1845 | create_black_surface(surface->compositor, |
| 1846 | surface, |
| 1847 | output->x, output->y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1848 | output->width, |
| 1849 | output->height); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1850 | |
| 1851 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1852 | wl_list_insert(&surface->layer_link, |
| 1853 | &shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1854 | weston_surface_damage(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static void |
| 1858 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 1859 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1860 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1861 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1862 | } |
| 1863 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1864 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1865 | set_fullscreen(struct shell_surface *shsurf, |
| 1866 | uint32_t method, |
| 1867 | uint32_t framerate, |
| 1868 | struct weston_output *output) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1869 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1870 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1871 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1872 | if (output) |
| 1873 | shsurf->output = output; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 1874 | else if (es->output) |
| 1875 | shsurf->output = es->output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1876 | else |
| 1877 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1878 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1879 | shsurf->fullscreen_output = shsurf->output; |
| 1880 | shsurf->fullscreen.type = method; |
| 1881 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1882 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1883 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1884 | shsurf->client->send_configure(shsurf->surface, 0, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 1885 | shsurf->output->width, |
| 1886 | shsurf->output->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1887 | } |
| 1888 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1889 | static void |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1890 | shell_surface_set_fullscreen(struct wl_client *client, |
| 1891 | struct wl_resource *resource, |
| 1892 | uint32_t method, |
| 1893 | uint32_t framerate, |
| 1894 | struct wl_resource *output_resource) |
| 1895 | { |
| 1896 | struct shell_surface *shsurf = resource->data; |
| 1897 | struct weston_output *output; |
| 1898 | |
| 1899 | if (output_resource) |
| 1900 | output = output_resource->data; |
| 1901 | else |
| 1902 | output = NULL; |
| 1903 | |
| 1904 | set_fullscreen(shsurf, method, framerate, output); |
| 1905 | } |
| 1906 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1907 | static const struct weston_pointer_grab_interface popup_grab_interface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 1908 | |
| 1909 | static void |
| 1910 | destroy_shell_seat(struct wl_listener *listener, void *data) |
| 1911 | { |
| 1912 | struct shell_seat *shseat = |
| 1913 | container_of(listener, |
| 1914 | struct shell_seat, seat_destroy_listener); |
| 1915 | struct shell_surface *shsurf, *prev = NULL; |
| 1916 | |
| 1917 | if (shseat->popup_grab.grab.interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1918 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 1919 | shseat->popup_grab.client = NULL; |
| 1920 | |
| 1921 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 1922 | shsurf->popup.shseat = NULL; |
| 1923 | if (prev) { |
| 1924 | wl_list_init(&prev->popup.grab_link); |
| 1925 | } |
| 1926 | prev = shsurf; |
| 1927 | } |
| 1928 | wl_list_init(&prev->popup.grab_link); |
| 1929 | } |
| 1930 | |
| 1931 | wl_list_remove(&shseat->seat_destroy_listener.link); |
| 1932 | free(shseat); |
| 1933 | } |
| 1934 | |
| 1935 | static struct shell_seat * |
| 1936 | create_shell_seat(struct weston_seat *seat) |
| 1937 | { |
| 1938 | struct shell_seat *shseat; |
| 1939 | |
| 1940 | shseat = calloc(1, sizeof *shseat); |
| 1941 | if (!shseat) { |
| 1942 | weston_log("no memory to allocate shell seat\n"); |
| 1943 | return NULL; |
| 1944 | } |
| 1945 | |
| 1946 | shseat->seat = seat; |
| 1947 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 1948 | |
| 1949 | shseat->seat_destroy_listener.notify = destroy_shell_seat; |
| 1950 | wl_signal_add(&seat->destroy_signal, |
| 1951 | &shseat->seat_destroy_listener); |
| 1952 | |
| 1953 | return shseat; |
| 1954 | } |
| 1955 | |
| 1956 | static struct shell_seat * |
| 1957 | get_shell_seat(struct weston_seat *seat) |
| 1958 | { |
| 1959 | struct wl_listener *listener; |
| 1960 | |
| 1961 | listener = wl_signal_get(&seat->destroy_signal, destroy_shell_seat); |
| 1962 | if (listener == NULL) |
| 1963 | return create_shell_seat(seat); |
| 1964 | |
| 1965 | return container_of(listener, |
| 1966 | struct shell_seat, seat_destroy_listener); |
| 1967 | } |
| 1968 | |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 1969 | static void |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1970 | popup_grab_focus(struct weston_pointer_grab *grab) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1971 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1972 | struct weston_pointer *pointer = grab->pointer; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1973 | struct weston_surface *surface; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 1974 | struct shell_seat *shseat = |
| 1975 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 1976 | struct wl_client *client = shseat->popup_grab.client; |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1977 | wl_fixed_t sx, sy; |
| 1978 | |
| 1979 | surface = weston_compositor_pick_surface(pointer->seat->compositor, |
| 1980 | pointer->x, pointer->y, |
| 1981 | &sx, &sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1982 | |
Pekka Paalanen | cb10843 | 2012-01-19 16:25:40 +0200 | [diff] [blame] | 1983 | if (surface && surface->resource.client == client) { |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 1984 | weston_pointer_set_focus(pointer, surface, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1985 | } else { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1986 | weston_pointer_set_focus(pointer, NULL, |
| 1987 | wl_fixed_from_int(0), |
| 1988 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | static void |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 1993 | popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1994 | { |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 1995 | struct weston_pointer *pointer = grab->pointer; |
| 1996 | wl_fixed_t sx, sy; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1997 | |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 1998 | if (pointer->focus_resource) { |
| 1999 | weston_surface_from_global_fixed(pointer->focus, |
| 2000 | pointer->x, pointer->y, |
| 2001 | &sx, &sy); |
| 2002 | wl_pointer_send_motion(pointer->focus_resource, time, sx, sy); |
| 2003 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2007 | popup_grab_button(struct weston_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2008 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2009 | { |
| 2010 | struct wl_resource *resource; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2011 | struct shell_seat *shseat = |
| 2012 | container_of(grab, struct shell_seat, popup_grab.grab); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2013 | struct wl_display *display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2014 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2015 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2016 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2017 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2018 | if (resource) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2019 | display = wl_client_get_display(resource->client); |
| 2020 | serial = wl_display_get_serial(display); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2021 | wl_pointer_send_button(resource, serial, time, button, state); |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2022 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2023 | (shseat->popup_grab.initial_up || |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2024 | time - shseat->seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2025 | popup_grab_end(grab->pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2026 | } |
| 2027 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2028 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2029 | shseat->popup_grab.initial_up = 1; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2030 | } |
| 2031 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2032 | static const struct weston_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2033 | popup_grab_focus, |
| 2034 | popup_grab_motion, |
| 2035 | popup_grab_button, |
| 2036 | }; |
| 2037 | |
| 2038 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2039 | popup_grab_end(struct weston_pointer *pointer) |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2040 | { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2041 | struct weston_pointer_grab *grab = pointer->grab; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2042 | struct shell_seat *shseat = |
| 2043 | container_of(grab, struct shell_seat, popup_grab.grab); |
| 2044 | struct shell_surface *shsurf; |
| 2045 | struct shell_surface *prev = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2046 | |
| 2047 | if (pointer->grab->interface == &popup_grab_interface) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2048 | weston_pointer_end_grab(grab->pointer); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2049 | shseat->popup_grab.client = NULL; |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2050 | shseat->popup_grab.grab.interface = NULL; |
| 2051 | assert(!wl_list_empty(&shseat->popup_grab.surfaces_list)); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2052 | /* Send the popup_done event to all the popups open */ |
| 2053 | wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) { |
| 2054 | wl_shell_surface_send_popup_done(&shsurf->resource); |
| 2055 | shsurf->popup.shseat = NULL; |
| 2056 | if (prev) { |
| 2057 | wl_list_init(&prev->popup.grab_link); |
| 2058 | } |
| 2059 | prev = shsurf; |
| 2060 | } |
| 2061 | wl_list_init(&prev->popup.grab_link); |
| 2062 | wl_list_init(&shseat->popup_grab.surfaces_list); |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | static void |
| 2067 | add_popup_grab(struct shell_surface *shsurf, struct shell_seat *shseat) |
| 2068 | { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2069 | struct weston_seat *seat = shseat->seat; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2070 | |
| 2071 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 2072 | shseat->popup_grab.client = shsurf->resource.client; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2073 | shseat->popup_grab.grab.interface = &popup_grab_interface; |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2074 | /* We must make sure here that this popup was opened after |
| 2075 | * a mouse press, and not just by moving around with other |
| 2076 | * popups already open. */ |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2077 | if (shseat->seat->pointer->button_count > 0) |
Giulio Camuffo | 1b4b61a | 2013-03-27 18:05:26 +0100 | [diff] [blame] | 2078 | shseat->popup_grab.initial_up = 0; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2079 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2080 | weston_pointer_start_grab(seat->pointer, &shseat->popup_grab.grab); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2081 | } |
| 2082 | wl_list_insert(&shseat->popup_grab.surfaces_list, &shsurf->popup.grab_link); |
| 2083 | } |
| 2084 | |
| 2085 | static void |
| 2086 | remove_popup_grab(struct shell_surface *shsurf) |
| 2087 | { |
| 2088 | struct shell_seat *shseat = shsurf->popup.shseat; |
| 2089 | |
| 2090 | wl_list_remove(&shsurf->popup.grab_link); |
| 2091 | wl_list_init(&shsurf->popup.grab_link); |
| 2092 | if (wl_list_empty(&shseat->popup_grab.surfaces_list)) { |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2093 | weston_pointer_end_grab(shseat->popup_grab.grab.pointer); |
Philipp Brüschweiler | 63e7be6 | 2013-04-15 21:09:54 +0200 | [diff] [blame] | 2094 | shseat->popup_grab.grab.interface = NULL; |
Kristian Høgsberg | 57e0907 | 2012-10-30 14:07:27 -0400 | [diff] [blame] | 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2099 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2100 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2101 | struct shell_seat *shseat = shsurf->popup.shseat; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2102 | struct weston_surface *es = shsurf->surface; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2103 | struct weston_surface *parent = shsurf->parent; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2104 | |
| 2105 | es->output = parent->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2106 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 2107 | weston_surface_set_transform_parent(es, parent); |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2108 | weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y); |
| 2109 | weston_surface_update_transform(es); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2110 | |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2111 | if (shseat->seat->pointer->grab_serial == shsurf->popup.serial) { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2112 | add_popup_grab(shsurf, shseat); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2113 | } else { |
| 2114 | wl_shell_surface_send_popup_done(&shsurf->resource); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2115 | shseat->popup_grab.client = NULL; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2116 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | static void |
| 2120 | shell_surface_set_popup(struct wl_client *client, |
| 2121 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2122 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2123 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2124 | struct wl_resource *parent_resource, |
| 2125 | int32_t x, int32_t y, uint32_t flags) |
| 2126 | { |
| 2127 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2128 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2129 | shsurf->type = SHELL_SURFACE_POPUP; |
| 2130 | shsurf->parent = parent_resource->data; |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2131 | shsurf->popup.shseat = get_shell_seat(seat_resource->data); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2132 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2133 | shsurf->popup.x = x; |
| 2134 | shsurf->popup.y = y; |
| 2135 | } |
| 2136 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2137 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2138 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2139 | shell_surface_move, |
| 2140 | shell_surface_resize, |
| 2141 | shell_surface_set_toplevel, |
| 2142 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2143 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2144 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 2145 | shell_surface_set_maximized, |
| 2146 | shell_surface_set_title, |
| 2147 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2148 | }; |
| 2149 | |
| 2150 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2151 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2152 | { |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2153 | if (!wl_list_empty(&shsurf->popup.grab_link)) { |
| 2154 | remove_popup_grab(shsurf); |
| 2155 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 2156 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2157 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 2158 | shell_surface_is_top_fullscreen(shsurf)) { |
| 2159 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 2160 | shsurf->fullscreen_output->origin); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2161 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2162 | |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 2163 | if (shsurf->fullscreen.black_surface) |
| 2164 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
| 2165 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2166 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 2167 | * we can always remove the listener. |
| 2168 | */ |
| 2169 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 2170 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 2171 | ping_timer_destroy(shsurf); |
Scott Moreau | 976a050 | 2013-03-07 10:15:17 -0700 | [diff] [blame] | 2172 | free(shsurf->title); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2173 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2174 | wl_list_remove(&shsurf->link); |
| 2175 | free(shsurf); |
| 2176 | } |
| 2177 | |
| 2178 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2179 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 2180 | { |
| 2181 | struct shell_surface *shsurf = resource->data; |
| 2182 | |
| 2183 | destroy_shell_surface(shsurf); |
| 2184 | } |
| 2185 | |
| 2186 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2187 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2188 | { |
| 2189 | struct shell_surface *shsurf = container_of(listener, |
| 2190 | struct shell_surface, |
| 2191 | surface_destroy_listener); |
| 2192 | |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 2193 | if (shsurf->resource.client) { |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2194 | wl_resource_destroy(&shsurf->resource); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 2195 | } else { |
| 2196 | wl_signal_emit(&shsurf->resource.destroy_signal, |
| 2197 | &shsurf->resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2198 | destroy_shell_surface(shsurf); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 2199 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2200 | } |
| 2201 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2202 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2203 | shell_surface_configure(struct weston_surface *, int32_t, int32_t, int32_t, int32_t); |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2204 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2205 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2206 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2207 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2208 | if (surface->configure == shell_surface_configure) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2209 | return surface->configure_private; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 2210 | else |
| 2211 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 2212 | } |
| 2213 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2214 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2215 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 2216 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2217 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2218 | struct shell_surface *shsurf; |
| 2219 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2220 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2221 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2222 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2223 | } |
| 2224 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2225 | shsurf = calloc(1, sizeof *shsurf); |
| 2226 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2227 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2228 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2229 | } |
| 2230 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2231 | surface->configure = shell_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2232 | surface->configure_private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2233 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2234 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2235 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2236 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 2237 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2238 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2239 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 2240 | shsurf->fullscreen.framerate = 0; |
| 2241 | shsurf->fullscreen.black_surface = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2242 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2243 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 2244 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2245 | wl_signal_init(&shsurf->resource.destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2246 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 2247 | wl_signal_add(&surface->resource.destroy_signal, |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2248 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2249 | |
| 2250 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 2251 | wl_list_init(&shsurf->link); |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 2252 | wl_list_init(&shsurf->popup.grab_link); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2253 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2254 | /* empty when not in use */ |
| 2255 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2256 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2257 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 2258 | wl_list_init(&shsurf->workspace_transform.link); |
| 2259 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2260 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2261 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2262 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2263 | shsurf->client = client; |
| 2264 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 2265 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | static void |
| 2269 | shell_get_shell_surface(struct wl_client *client, |
| 2270 | struct wl_resource *resource, |
| 2271 | uint32_t id, |
| 2272 | struct wl_resource *surface_resource) |
| 2273 | { |
| 2274 | struct weston_surface *surface = surface_resource->data; |
| 2275 | struct desktop_shell *shell = resource->data; |
| 2276 | struct shell_surface *shsurf; |
| 2277 | |
| 2278 | if (get_shell_surface(surface)) { |
| 2279 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2280 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2281 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2282 | return; |
| 2283 | } |
| 2284 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 2285 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2286 | if (!shsurf) { |
| 2287 | wl_resource_post_error(surface_resource, |
| 2288 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2289 | "surface->configure already set"); |
| 2290 | return; |
| 2291 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2292 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2293 | shsurf->resource.destroy = shell_destroy_shell_surface; |
| 2294 | shsurf->resource.object.id = id; |
| 2295 | shsurf->resource.object.interface = &wl_shell_surface_interface; |
| 2296 | shsurf->resource.object.implementation = |
| 2297 | (void (**)(void)) &shell_surface_implementation; |
| 2298 | shsurf->resource.data = shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 2299 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 2300 | wl_client_add_resource(client, &shsurf->resource); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 2304 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2305 | }; |
| 2306 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2307 | static void |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 2308 | shell_fade(struct desktop_shell *shell, enum fade_type type); |
| 2309 | |
| 2310 | static int |
| 2311 | screensaver_timeout(void *data) |
| 2312 | { |
| 2313 | struct desktop_shell *shell = data; |
| 2314 | |
| 2315 | shell_fade(shell, FADE_OUT); |
| 2316 | |
| 2317 | return 1; |
| 2318 | } |
| 2319 | |
| 2320 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2321 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2322 | { |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2323 | struct desktop_shell *shell = |
| 2324 | container_of(proc, struct desktop_shell, screensaver.process); |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2325 | |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2326 | proc->pid = 0; |
Ander Conselvan de Oliveira | 18639f8 | 2013-02-15 18:44:19 +0200 | [diff] [blame] | 2327 | |
| 2328 | if (shell->locked) |
Ander Conselvan de Oliveira | b17537e | 2013-02-22 14:16:18 +0200 | [diff] [blame] | 2329 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2333 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2334 | { |
| 2335 | if (shell->screensaver.binding) |
| 2336 | return; |
| 2337 | |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2338 | if (!shell->screensaver.path) { |
| 2339 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2340 | return; |
Ander Conselvan de Oliveira | dda9d78 | 2013-02-22 14:16:19 +0200 | [diff] [blame] | 2341 | } |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2342 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2343 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2344 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 2345 | return; |
| 2346 | } |
| 2347 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2348 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2349 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2350 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2351 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2355 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2356 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 2357 | if (shell->screensaver.process.pid == 0) |
| 2358 | return; |
| 2359 | |
| 2360 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2364 | configure_static_surface(struct weston_surface *es, struct weston_layer *layer, int32_t width, int32_t height) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2365 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2366 | struct weston_surface *s, *next; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2367 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2368 | if (width == 0) |
| 2369 | return; |
| 2370 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2371 | wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) { |
| 2372 | if (s->output == es->output && s != es) { |
| 2373 | weston_surface_unmap(s); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2374 | s->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2375 | } |
| 2376 | } |
| 2377 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2378 | weston_surface_configure(es, es->output->x, es->output->y, width, height); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2379 | |
| 2380 | if (wl_list_empty(&es->layer_link)) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2381 | wl_list_insert(&layer->surface_list, &es->layer_link); |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 2382 | weston_compositor_schedule_repaint(es->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2383 | } |
| 2384 | } |
| 2385 | |
| 2386 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2387 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2388 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2389 | struct desktop_shell *shell = es->configure_private; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2390 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2391 | configure_static_surface(es, &shell->background_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2395 | desktop_shell_set_background(struct wl_client *client, |
| 2396 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2397 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2398 | struct wl_resource *surface_resource) |
| 2399 | { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2400 | struct desktop_shell *shell = resource->data; |
| 2401 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2402 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2403 | if (surface->configure) { |
| 2404 | wl_resource_post_error(surface_resource, |
| 2405 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2406 | "surface role already assigned"); |
| 2407 | return; |
| 2408 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2409 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2410 | surface->configure = background_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2411 | surface->configure_private = shell; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 2412 | surface->output = output_resource->data; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2413 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2414 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2415 | surface->output->width, |
| 2416 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2420 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2421 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2422 | struct desktop_shell *shell = es->configure_private; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2423 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2424 | configure_static_surface(es, &shell->panel_layer, width, height); |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2428 | desktop_shell_set_panel(struct wl_client *client, |
| 2429 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2430 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2431 | struct wl_resource *surface_resource) |
| 2432 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2433 | struct desktop_shell *shell = resource->data; |
| 2434 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2435 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2436 | if (surface->configure) { |
| 2437 | wl_resource_post_error(surface_resource, |
| 2438 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2439 | "surface role already assigned"); |
| 2440 | return; |
| 2441 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2442 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2443 | surface->configure = panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2444 | surface->configure_private = shell; |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2445 | surface->output = output_resource->data; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2446 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2447 | surface_resource, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2448 | surface->output->width, |
| 2449 | surface->output->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2450 | } |
| 2451 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2452 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2453 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2454 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2455 | struct desktop_shell *shell = surface->configure_private; |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2456 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2457 | if (width == 0) |
| 2458 | return; |
| 2459 | |
Kristian Høgsberg | b9f1c52 | 2013-05-14 20:59:02 -0400 | [diff] [blame] | 2460 | surface->geometry.width = width; |
| 2461 | surface->geometry.height = height; |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2462 | center_on_output(surface, get_default_output(shell->compositor)); |
| 2463 | |
| 2464 | if (!weston_surface_is_mapped(surface)) { |
| 2465 | wl_list_insert(&shell->lock_layer.surface_list, |
| 2466 | &surface->layer_link); |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 2467 | weston_surface_update_transform(surface); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2468 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2473 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2474 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2475 | struct desktop_shell *shell = |
| 2476 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2477 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2478 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2479 | shell->lock_surface = NULL; |
| 2480 | } |
| 2481 | |
| 2482 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2483 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 2484 | struct wl_resource *resource, |
| 2485 | struct wl_resource *surface_resource) |
| 2486 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2487 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2488 | struct weston_surface *surface = surface_resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2489 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2490 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2491 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2492 | if (!shell->locked) |
| 2493 | return; |
| 2494 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2495 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2496 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2497 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
| 2498 | wl_signal_add(&surface_resource->destroy_signal, |
| 2499 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2500 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2501 | surface->configure = lock_surface_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2502 | surface->configure_private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2506 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2507 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2508 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2509 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2510 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2511 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2512 | wl_list_remove(&shell->lock_layer.link); |
| 2513 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 2514 | &shell->fullscreen_layer.link); |
| 2515 | wl_list_insert(&shell->fullscreen_layer.link, |
| 2516 | &shell->panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2517 | if (shell->showing_input_panels) { |
| 2518 | wl_list_insert(&shell->panel_layer.link, |
| 2519 | &shell->input_panel_layer.link); |
| 2520 | wl_list_insert(&shell->input_panel_layer.link, |
| 2521 | &ws->layer.link); |
| 2522 | } else { |
| 2523 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 2524 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2525 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2526 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 2527 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2528 | shell->locked = false; |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2529 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 2530 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | static void |
| 2534 | desktop_shell_unlock(struct wl_client *client, |
| 2535 | struct wl_resource *resource) |
| 2536 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2537 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2538 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2539 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2540 | |
| 2541 | if (shell->locked) |
| 2542 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2543 | } |
| 2544 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2545 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2546 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2547 | struct wl_resource *resource, |
| 2548 | struct wl_resource *surface_resource) |
| 2549 | { |
| 2550 | struct desktop_shell *shell = resource->data; |
| 2551 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2552 | shell->grab_surface = surface_resource->data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2553 | } |
| 2554 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 2555 | static void |
| 2556 | desktop_shell_desktop_ready(struct wl_client *client, |
| 2557 | struct wl_resource *resource) |
| 2558 | { |
| 2559 | struct desktop_shell *shell = resource->data; |
| 2560 | |
| 2561 | shell_fade_startup(shell); |
| 2562 | } |
| 2563 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2564 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 2565 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2566 | desktop_shell_set_panel, |
| 2567 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2568 | desktop_shell_unlock, |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 2569 | desktop_shell_set_grab_surface, |
| 2570 | desktop_shell_desktop_ready |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2571 | }; |
| 2572 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2573 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2574 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2575 | { |
| 2576 | struct shell_surface *shsurf; |
| 2577 | |
| 2578 | shsurf = get_shell_surface(surface); |
| 2579 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2580 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2581 | return shsurf->type; |
| 2582 | } |
| 2583 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2584 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2585 | 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] | 2586 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2587 | struct weston_surface *focus = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2588 | (struct weston_surface *) seat->pointer->focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2589 | struct weston_surface *surface; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2590 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2591 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2592 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2593 | if (surface == NULL) |
| 2594 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2595 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2596 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 2597 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 2598 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2599 | return; |
| 2600 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2601 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2605 | 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] | 2606 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2607 | struct weston_surface *focus = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2608 | (struct weston_surface *) seat->pointer->focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2609 | struct weston_surface *surface; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2610 | uint32_t edges = 0; |
| 2611 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2612 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2613 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2614 | surface = weston_surface_get_main_surface(focus); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2615 | if (surface == NULL) |
| 2616 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2617 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2618 | shsurf = get_shell_surface(surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 2619 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN || |
| 2620 | shsurf->type == SHELL_SURFACE_MAXIMIZED) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2621 | return; |
| 2622 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 2623 | weston_surface_from_global(surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2624 | wl_fixed_to_int(seat->pointer->grab_x), |
| 2625 | wl_fixed_to_int(seat->pointer->grab_y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2626 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2627 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2628 | if (x < surface->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2629 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2630 | else if (x < 2 * surface->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2631 | edges |= 0; |
| 2632 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2633 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2634 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2635 | if (y < surface->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2636 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2637 | else if (y < 2 * surface->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2638 | edges |= 0; |
| 2639 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2640 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2641 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 2642 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2646 | 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] | 2647 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2648 | { |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2649 | float step = 0.005; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2650 | struct shell_surface *shsurf; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2651 | struct weston_surface *focus = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2652 | (struct weston_surface *) seat->pointer->focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2653 | struct weston_surface *surface; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2654 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2655 | /* XXX: broken for windows containing sub-surfaces */ |
| 2656 | surface = weston_surface_get_main_surface(focus); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2657 | if (surface == NULL) |
| 2658 | return; |
| 2659 | |
| 2660 | shsurf = get_shell_surface(surface); |
| 2661 | if (!shsurf) |
| 2662 | return; |
| 2663 | |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2664 | surface->alpha -= wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2665 | |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2666 | if (surface->alpha > 1.0) |
| 2667 | surface->alpha = 1.0; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2668 | if (surface->alpha < step) |
| 2669 | surface->alpha = step; |
| 2670 | |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 2671 | weston_surface_geometry_dirty(surface); |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2672 | weston_surface_damage(surface); |
| 2673 | } |
| 2674 | |
| 2675 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2676 | 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] | 2677 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2678 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2679 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 2680 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2681 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2682 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2683 | |
| 2684 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2685 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2686 | wl_fixed_to_double(seat->pointer->x), |
| 2687 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2688 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2689 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2690 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2691 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2692 | increment = -output->zoom.increment; |
| 2693 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2694 | /* For every pixel zoom 20th of a step */ |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2695 | increment = output->zoom.increment * |
Jonas Ådahl | b0b87ba | 2012-09-27 18:40:42 +0200 | [diff] [blame] | 2696 | -wl_fixed_to_double(value) / 20.0; |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2697 | else |
| 2698 | increment = 0; |
| 2699 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2700 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 2701 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2702 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2703 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2704 | else if (output->zoom.level > output->zoom.max_level) |
| 2705 | output->zoom.level = output->zoom.max_level; |
Ville Syrjälä | aa628d0 | 2012-11-16 11:48:47 +0200 | [diff] [blame] | 2706 | else if (!output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2707 | output->zoom.active = 1; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2708 | output->disable_planes++; |
| 2709 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2710 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2711 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2712 | |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 2713 | weston_output_update_zoom(output, output->zoom.type); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2714 | } |
| 2715 | } |
| 2716 | } |
| 2717 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2718 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2719 | 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] | 2720 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2721 | { |
| 2722 | do_zoom(seat, time, 0, axis, value); |
| 2723 | } |
| 2724 | |
| 2725 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2726 | 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] | 2727 | void *data) |
| 2728 | { |
| 2729 | do_zoom(seat, time, key, 0, 0); |
| 2730 | } |
| 2731 | |
| 2732 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2733 | terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2734 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2735 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2736 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2737 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2738 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | static void |
Kristian Høgsberg | be6403e | 2013-05-08 21:03:21 -0400 | [diff] [blame] | 2742 | rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2743 | { |
| 2744 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2745 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2746 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2747 | struct shell_surface *shsurf = rotate->base.shsurf; |
| 2748 | struct weston_surface *surface; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2749 | float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2750 | |
| 2751 | if (!shsurf) |
| 2752 | return; |
| 2753 | |
| 2754 | surface = shsurf->surface; |
| 2755 | |
| 2756 | cx = 0.5f * surface->geometry.width; |
| 2757 | cy = 0.5f * surface->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2758 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2759 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 2760 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2761 | r = sqrtf(dx * dx + dy * dy); |
| 2762 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2763 | wl_list_remove(&shsurf->rotation.transform.link); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 2764 | weston_surface_geometry_dirty(shsurf->surface); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2765 | |
| 2766 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2767 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2768 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2769 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2770 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 2771 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2772 | |
| 2773 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2774 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2775 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2776 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2777 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2778 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 2779 | wl_list_insert( |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2780 | &shsurf->surface->geometry.transformation_list, |
| 2781 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2782 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2783 | wl_list_init(&shsurf->rotation.transform.link); |
| 2784 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2785 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2786 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2787 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2788 | /* We need to adjust the position of the surface |
| 2789 | * in case it was resized in a rotated state before */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2790 | cposx = surface->geometry.x + cx; |
| 2791 | cposy = surface->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2792 | dposx = rotate->center.x - cposx; |
| 2793 | dposy = rotate->center.y - cposy; |
| 2794 | if (dposx != 0.0f || dposy != 0.0f) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2795 | weston_surface_set_position(surface, |
| 2796 | surface->geometry.x + dposx, |
| 2797 | surface->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2798 | } |
| 2799 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2800 | /* Repaint implies weston_surface_update_transform(), which |
| 2801 | * lazily applies the damage due to rotation update. |
| 2802 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2803 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | static void |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2807 | rotate_grab_button(struct weston_pointer_grab *grab, |
| 2808 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2809 | { |
| 2810 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2811 | container_of(grab, struct rotate_grab, base.grab); |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2812 | struct weston_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2813 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2814 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2815 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2816 | if (pointer->button_count == 0 && |
| 2817 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2818 | if (shsurf) |
| 2819 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 2820 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2821 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2822 | free(rotate); |
| 2823 | } |
| 2824 | } |
| 2825 | |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 2826 | static const struct weston_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2827 | noop_grab_focus, |
| 2828 | rotate_grab_motion, |
| 2829 | rotate_grab_button, |
| 2830 | }; |
| 2831 | |
| 2832 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2833 | surface_rotate(struct shell_surface *surface, struct weston_seat *seat) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2834 | { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2835 | struct rotate_grab *rotate; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 2836 | float dx, dy; |
| 2837 | float r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2838 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2839 | rotate = malloc(sizeof *rotate); |
| 2840 | if (!rotate) |
| 2841 | return; |
| 2842 | |
Kristian Høgsberg | b2af93e | 2012-06-07 20:10:23 -0400 | [diff] [blame] | 2843 | weston_surface_to_global_float(surface->surface, |
| 2844 | surface->surface->geometry.width / 2, |
| 2845 | surface->surface->geometry.height / 2, |
| 2846 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2847 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2848 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 2849 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2850 | r = sqrtf(dx * dx + dy * dy); |
| 2851 | if (r > 20.0f) { |
| 2852 | struct weston_matrix inverse; |
| 2853 | |
| 2854 | weston_matrix_init(&inverse); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 2855 | weston_matrix_rotate_xy(&inverse, dx / r, -dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2856 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2857 | |
| 2858 | weston_matrix_init(&rotate->rotation); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 2859 | weston_matrix_rotate_xy(&rotate->rotation, dx / r, dy / r); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2860 | } else { |
| 2861 | weston_matrix_init(&surface->rotation.rotation); |
| 2862 | weston_matrix_init(&rotate->rotation); |
| 2863 | } |
| 2864 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2865 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 2866 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2870 | 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] | 2871 | void *data) |
| 2872 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2873 | struct weston_surface *focus = |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2874 | (struct weston_surface *) seat->pointer->focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2875 | struct weston_surface *base_surface; |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2876 | struct shell_surface *surface; |
| 2877 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2878 | base_surface = weston_surface_get_main_surface(focus); |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2879 | if (base_surface == NULL) |
| 2880 | return; |
| 2881 | |
| 2882 | surface = get_shell_surface(base_surface); |
Rafal Mielniczuk | 23c6759 | 2013-03-11 19:26:53 +0100 | [diff] [blame] | 2883 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN || |
| 2884 | surface->type == SHELL_SURFACE_MAXIMIZED) |
Kristian Høgsberg | 0c36903 | 2013-02-14 21:31:44 -0500 | [diff] [blame] | 2885 | return; |
| 2886 | |
| 2887 | surface_rotate(surface, seat); |
| 2888 | } |
| 2889 | |
| 2890 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2891 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 2892 | { |
| 2893 | struct workspace *ws; |
| 2894 | struct weston_surface *surface, *prev; |
| 2895 | |
| 2896 | ws = get_current_workspace(shell); |
| 2897 | wl_list_for_each_reverse_safe(surface, prev, |
| 2898 | &shell->fullscreen_layer.surface_list, |
| 2899 | layer_link) |
| 2900 | weston_surface_restack(surface, &ws->layer.surface_list); |
| 2901 | } |
| 2902 | |
| 2903 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2904 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2905 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2906 | { |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2907 | struct weston_surface *main_surface; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2908 | struct focus_state *state; |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 2909 | struct workspace *ws; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2910 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2911 | main_surface = weston_surface_get_main_surface(es); |
| 2912 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2913 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2914 | |
Jonas Ådahl | 8538b22 | 2012-08-29 22:13:03 +0200 | [diff] [blame] | 2915 | state = ensure_focus_state(shell, seat); |
| 2916 | if (state == NULL) |
| 2917 | return; |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2918 | |
| 2919 | state->keyboard_focus = es; |
| 2920 | wl_list_remove(&state->surface_destroy_listener.link); |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 2921 | wl_signal_add(&es->resource.destroy_signal, |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2922 | &state->surface_destroy_listener); |
| 2923 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2924 | switch (get_shell_surface_type(main_surface)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2925 | case SHELL_SURFACE_FULLSCREEN: |
| 2926 | /* should on top of panels */ |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2927 | shell_stack_fullscreen(get_shell_surface(main_surface)); |
| 2928 | shell_configure_fullscreen(get_shell_surface(main_surface)); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2929 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2930 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2931 | ws = get_current_workspace(shell); |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2932 | weston_surface_restack(main_surface, &ws->layer.surface_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2933 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2934 | } |
| 2935 | } |
| 2936 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2937 | /* no-op func for checking black surface */ |
| 2938 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2939 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2940 | { |
| 2941 | } |
| 2942 | |
Quentin Glidic | c0d79ce | 2013-01-29 14:16:13 +0100 | [diff] [blame] | 2943 | static bool |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2944 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 2945 | { |
| 2946 | if (es->configure == black_surface_configure) { |
| 2947 | if (fs_surface) |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 2948 | *fs_surface = (struct weston_surface *)es->configure_private; |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2949 | return true; |
| 2950 | } |
| 2951 | return false; |
| 2952 | } |
| 2953 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2954 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 2955 | click_to_activate_binding(struct weston_seat *seat, uint32_t time, uint32_t button, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2956 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2957 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2958 | struct weston_seat *ws = (struct weston_seat *) seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2959 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2960 | struct weston_surface *focus; |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2961 | struct weston_surface *main_surface; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2962 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2963 | focus = (struct weston_surface *) seat->pointer->focus; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 2964 | if (!focus) |
| 2965 | return; |
| 2966 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2967 | if (is_black_surface(focus, &main_surface)) |
| 2968 | focus = main_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2969 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2970 | main_surface = weston_surface_get_main_surface(focus); |
| 2971 | if (get_shell_surface_type(main_surface) == SHELL_SURFACE_NONE) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2972 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 2973 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2974 | if (seat->pointer->grab == &seat->pointer->default_grab) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2975 | activate(shell, focus, ws); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 2979 | lock(struct desktop_shell *shell) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2980 | { |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2981 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2982 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2983 | if (shell->locked) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2984 | weston_compositor_sleep(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2985 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2986 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2987 | |
| 2988 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2989 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2990 | /* Hide all surfaces by removing the fullscreen, panel and |
| 2991 | * toplevel layers. This way nothing else can show or receive |
| 2992 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2993 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2994 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2995 | wl_list_remove(&shell->fullscreen_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 2996 | if (shell->showing_input_panels) |
| 2997 | wl_list_remove(&shell->input_panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2998 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2999 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 3000 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3001 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3002 | launch_screensaver(shell); |
| 3003 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3004 | /* TODO: disable bindings that should not work while locked. */ |
| 3005 | |
| 3006 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3010 | unlock(struct desktop_shell *shell) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3011 | { |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 3012 | if (!shell->locked || shell->lock_surface) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3013 | shell_fade(shell, FADE_IN); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3014 | return; |
| 3015 | } |
| 3016 | |
| 3017 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 3018 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3019 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3020 | return; |
| 3021 | } |
| 3022 | |
| 3023 | if (shell->prepare_event_sent) |
| 3024 | return; |
| 3025 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3026 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3027 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | static void |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3031 | shell_fade_done(struct weston_surface_animation *animation, void *data) |
| 3032 | { |
| 3033 | struct desktop_shell *shell = data; |
| 3034 | |
| 3035 | shell->fade.animation = NULL; |
| 3036 | |
| 3037 | switch (shell->fade.type) { |
| 3038 | case FADE_IN: |
| 3039 | weston_surface_destroy(shell->fade.surface); |
| 3040 | shell->fade.surface = NULL; |
| 3041 | break; |
| 3042 | case FADE_OUT: |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3043 | lock(shell); |
| 3044 | break; |
| 3045 | } |
| 3046 | } |
| 3047 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 3048 | static struct weston_surface * |
| 3049 | shell_fade_create_surface(struct desktop_shell *shell) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3050 | { |
| 3051 | struct weston_compositor *compositor = shell->compositor; |
| 3052 | struct weston_surface *surface; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 3053 | |
| 3054 | surface = weston_surface_create(compositor); |
| 3055 | if (!surface) |
| 3056 | return NULL; |
| 3057 | |
| 3058 | weston_surface_configure(surface, 0, 0, 8192, 8192); |
| 3059 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); |
| 3060 | wl_list_insert(&compositor->fade_layer.surface_list, |
| 3061 | &surface->layer_link); |
| 3062 | pixman_region32_init(&surface->input); |
| 3063 | |
| 3064 | return surface; |
| 3065 | } |
| 3066 | |
| 3067 | static void |
| 3068 | shell_fade(struct desktop_shell *shell, enum fade_type type) |
| 3069 | { |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3070 | float tint; |
| 3071 | |
| 3072 | switch (type) { |
| 3073 | case FADE_IN: |
| 3074 | tint = 0.0; |
| 3075 | break; |
| 3076 | case FADE_OUT: |
| 3077 | tint = 1.0; |
| 3078 | break; |
| 3079 | default: |
| 3080 | weston_log("shell: invalid fade type\n"); |
| 3081 | return; |
| 3082 | } |
| 3083 | |
| 3084 | shell->fade.type = type; |
| 3085 | |
| 3086 | if (shell->fade.surface == NULL) { |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 3087 | shell->fade.surface = shell_fade_create_surface(shell); |
| 3088 | if (!shell->fade.surface) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3089 | return; |
| 3090 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 3091 | shell->fade.surface->alpha = 1.0 - tint; |
| 3092 | weston_surface_update_transform(shell->fade.surface); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | if (shell->fade.animation) |
| 3096 | weston_fade_update(shell->fade.animation, |
| 3097 | shell->fade.surface->alpha, tint, 30.0); |
| 3098 | else |
| 3099 | shell->fade.animation = |
| 3100 | weston_fade_run(shell->fade.surface, |
| 3101 | 1.0 - tint, tint, 30.0, |
| 3102 | shell_fade_done, shell); |
| 3103 | } |
| 3104 | |
| 3105 | static void |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 3106 | do_shell_fade_startup(void *data) |
| 3107 | { |
| 3108 | struct desktop_shell *shell = data; |
| 3109 | |
| 3110 | shell_fade(shell, FADE_IN); |
| 3111 | } |
| 3112 | |
| 3113 | static void |
| 3114 | shell_fade_startup(struct desktop_shell *shell) |
| 3115 | { |
| 3116 | struct wl_event_loop *loop; |
| 3117 | |
| 3118 | if (!shell->fade.startup_timer) |
| 3119 | return; |
| 3120 | |
| 3121 | wl_event_source_remove(shell->fade.startup_timer); |
| 3122 | shell->fade.startup_timer = NULL; |
| 3123 | |
| 3124 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 3125 | wl_event_loop_add_idle(loop, do_shell_fade_startup, shell); |
| 3126 | } |
| 3127 | |
| 3128 | static int |
| 3129 | fade_startup_timeout(void *data) |
| 3130 | { |
| 3131 | struct desktop_shell *shell = data; |
| 3132 | |
| 3133 | shell_fade_startup(shell); |
| 3134 | return 0; |
| 3135 | } |
| 3136 | |
| 3137 | static void |
| 3138 | shell_fade_init(struct desktop_shell *shell) |
| 3139 | { |
| 3140 | /* Make compositor output all black, and wait for the desktop-shell |
| 3141 | * client to signal it is ready, then fade in. The timer triggers a |
| 3142 | * fade-in, in case the desktop-shell client takes too long. |
| 3143 | */ |
| 3144 | |
| 3145 | struct wl_event_loop *loop; |
| 3146 | |
| 3147 | if (shell->fade.surface != NULL) { |
| 3148 | weston_log("%s: warning: fade surface already exists\n", |
| 3149 | __func__); |
| 3150 | return; |
| 3151 | } |
| 3152 | |
| 3153 | shell->fade.surface = shell_fade_create_surface(shell); |
| 3154 | if (!shell->fade.surface) |
| 3155 | return; |
| 3156 | |
| 3157 | weston_surface_update_transform(shell->fade.surface); |
| 3158 | weston_surface_damage(shell->fade.surface); |
| 3159 | |
| 3160 | loop = wl_display_get_event_loop(shell->compositor->wl_display); |
| 3161 | shell->fade.startup_timer = |
| 3162 | wl_event_loop_add_timer(loop, fade_startup_timeout, shell); |
| 3163 | wl_event_source_timer_update(shell->fade.startup_timer, 15000); |
| 3164 | } |
| 3165 | |
| 3166 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3167 | idle_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3168 | { |
| 3169 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3170 | container_of(listener, struct desktop_shell, idle_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3171 | |
| 3172 | shell_fade(shell, FADE_OUT); |
| 3173 | /* lock() is called from shell_fade_done() */ |
| 3174 | } |
| 3175 | |
| 3176 | static void |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3177 | wake_handler(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3178 | { |
| 3179 | struct desktop_shell *shell = |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3180 | container_of(listener, struct desktop_shell, wake_listener); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3181 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3182 | unlock(shell); |
| 3183 | } |
| 3184 | |
| 3185 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3186 | show_input_panels(struct wl_listener *listener, void *data) |
| 3187 | { |
| 3188 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3189 | container_of(listener, struct desktop_shell, |
| 3190 | show_input_panel_listener); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3191 | struct input_panel_surface *surface, *next; |
| 3192 | struct weston_surface *ws; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3193 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3194 | shell->text_input.surface = (struct weston_surface*)data; |
| 3195 | |
Jan Arne Petersen | 451a971 | 2013-02-11 15:10:11 +0100 | [diff] [blame] | 3196 | if (shell->showing_input_panels) |
| 3197 | return; |
| 3198 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3199 | shell->showing_input_panels = true; |
| 3200 | |
Jan Arne Petersen | cf18a32 | 2012-11-07 15:32:54 +0100 | [diff] [blame] | 3201 | if (!shell->locked) |
| 3202 | wl_list_insert(&shell->panel_layer.link, |
| 3203 | &shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3204 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3205 | wl_list_for_each_safe(surface, next, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3206 | &shell->input_panel.surfaces, link) { |
| 3207 | ws = surface->surface; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 3208 | if (!ws->buffer_ref.buffer) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3209 | continue; |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3210 | wl_list_insert(&shell->input_panel_layer.surface_list, |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3211 | &ws->layer_link); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 3212 | weston_surface_geometry_dirty(ws); |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 3213 | weston_surface_update_transform(ws); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3214 | weston_surface_damage(ws); |
| 3215 | weston_slide_run(ws, ws->geometry.height, 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | static void |
| 3220 | hide_input_panels(struct wl_listener *listener, void *data) |
| 3221 | { |
| 3222 | struct desktop_shell *shell = |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3223 | container_of(listener, struct desktop_shell, |
| 3224 | hide_input_panel_listener); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3225 | struct weston_surface *surface, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3226 | |
Jan Arne Petersen | 6138197 | 2013-01-31 15:52:21 +0100 | [diff] [blame] | 3227 | if (!shell->showing_input_panels) |
| 3228 | return; |
| 3229 | |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3230 | shell->showing_input_panels = false; |
| 3231 | |
Jan Arne Petersen | 82ec909 | 2012-12-03 15:36:02 +0100 | [diff] [blame] | 3232 | if (!shell->locked) |
| 3233 | wl_list_remove(&shell->input_panel_layer.link); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3234 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3235 | wl_list_for_each_safe(surface, next, |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 3236 | &shell->input_panel_layer.surface_list, layer_link) |
| 3237 | weston_surface_unmap(surface); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | static void |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3241 | update_input_panels(struct wl_listener *listener, void *data) |
| 3242 | { |
| 3243 | struct desktop_shell *shell = |
| 3244 | container_of(listener, struct desktop_shell, |
| 3245 | update_input_panel_listener); |
| 3246 | |
| 3247 | memcpy(&shell->text_input.cursor_rectangle, data, sizeof(pixman_box32_t)); |
| 3248 | } |
| 3249 | |
| 3250 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3251 | center_on_output(struct weston_surface *surface, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3252 | { |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3253 | int32_t surf_x, surf_y, width, height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3254 | float x, y; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3255 | |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3256 | surface_subsurfaces_boundingbox(surface, &surf_x, &surf_y, &width, &height); |
| 3257 | |
| 3258 | x = output->x + (output->width - width) / 2 - surf_x / 2; |
| 3259 | y = output->y + (output->height - height) / 2 - surf_y / 2; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3260 | |
| 3261 | weston_surface_configure(surface, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | static void |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3265 | weston_surface_set_initial_position (struct weston_surface *surface, |
| 3266 | struct desktop_shell *shell) |
| 3267 | { |
| 3268 | struct weston_compositor *compositor = shell->compositor; |
| 3269 | int ix = 0, iy = 0; |
| 3270 | int range_x, range_y; |
| 3271 | int dx, dy, x, y, panel_height; |
| 3272 | struct weston_output *output, *target_output = NULL; |
| 3273 | struct weston_seat *seat; |
| 3274 | |
| 3275 | /* As a heuristic place the new window on the same output as the |
| 3276 | * pointer. Falling back to the output containing 0, 0. |
| 3277 | * |
| 3278 | * TODO: Do something clever for touch too? |
| 3279 | */ |
| 3280 | wl_list_for_each(seat, &compositor->seat_list, link) { |
Kristian Høgsberg | 2bf8762 | 2013-05-07 23:17:41 -0400 | [diff] [blame] | 3281 | if (seat->pointer) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 3282 | ix = wl_fixed_to_int(seat->pointer->x); |
| 3283 | iy = wl_fixed_to_int(seat->pointer->y); |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3284 | break; |
| 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3289 | if (pixman_region32_contains_point(&output->region, ix, iy, NULL)) { |
| 3290 | target_output = output; |
| 3291 | break; |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | if (!target_output) { |
| 3296 | weston_surface_set_position(surface, 10 + random() % 400, |
| 3297 | 10 + random() % 400); |
| 3298 | return; |
| 3299 | } |
| 3300 | |
| 3301 | /* Valid range within output where the surface will still be onscreen. |
| 3302 | * If this is negative it means that the surface is bigger than |
| 3303 | * output. |
| 3304 | */ |
| 3305 | panel_height = get_output_panel_height(shell, target_output); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3306 | range_x = target_output->width - surface->geometry.width; |
| 3307 | range_y = (target_output->height - panel_height) - |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3308 | surface->geometry.height; |
| 3309 | |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 3310 | if (range_x > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3311 | dx = random() % range_x; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3312 | else |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 3313 | dx = 0; |
| 3314 | |
| 3315 | if (range_y > 0) |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3316 | dy = panel_height + random() % range_y; |
Rob Bradford | 4cb88c7 | 2012-08-13 15:18:44 +0100 | [diff] [blame] | 3317 | else |
| 3318 | dy = panel_height; |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3319 | |
| 3320 | x = target_output->x + dx; |
| 3321 | y = target_output->y + dy; |
| 3322 | |
| 3323 | weston_surface_set_position (surface, x, y); |
| 3324 | } |
| 3325 | |
| 3326 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3327 | map(struct desktop_shell *shell, struct weston_surface *surface, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 3328 | int32_t width, int32_t height, int32_t sx, int32_t sy) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3329 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3330 | struct weston_compositor *compositor = shell->compositor; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3331 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 3332 | enum shell_surface_type surface_type = shsurf->type; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 3333 | struct weston_surface *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 3334 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3335 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3336 | int panel_height = 0; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3337 | int32_t surf_x, surf_y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3338 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 3339 | surface->geometry.width = width; |
| 3340 | surface->geometry.height = height; |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 3341 | weston_surface_geometry_dirty(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3342 | |
| 3343 | /* initial positioning, see also configure() */ |
| 3344 | switch (surface_type) { |
| 3345 | case SHELL_SURFACE_TOPLEVEL: |
Rob Bradford | ac63e5b | 2012-08-13 14:07:52 +0100 | [diff] [blame] | 3346 | weston_surface_set_initial_position(surface, shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3347 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3348 | case SHELL_SURFACE_FULLSCREEN: |
Kristian Høgsberg | e4d3a2b | 2012-07-09 21:43:22 -0400 | [diff] [blame] | 3349 | center_on_output(surface, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3350 | shell_map_fullscreen(shsurf); |
| 3351 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3352 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3353 | /* use surface configure to set the geometry */ |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3354 | panel_height = get_output_panel_height(shell,surface->output); |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3355 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 3356 | NULL, NULL); |
| 3357 | weston_surface_set_position(surface, shsurf->output->x - surf_x, |
| 3358 | shsurf->output->y + panel_height - surf_y); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3359 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 3360 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 3361 | shell_map_popup(shsurf); |
Rob Bradford | db99938 | 2012-12-06 12:07:48 +0000 | [diff] [blame] | 3362 | break; |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 3363 | case SHELL_SURFACE_NONE: |
| 3364 | weston_surface_set_position(surface, |
| 3365 | surface->geometry.x + sx, |
| 3366 | surface->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 3367 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3368 | default: |
| 3369 | ; |
| 3370 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3371 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 3372 | /* surface stacking order, see also activate() */ |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 3373 | switch (surface_type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 3374 | case SHELL_SURFACE_POPUP: |
| 3375 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 3376 | parent = shsurf->parent; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 3377 | wl_list_insert(parent->layer_link.prev, &surface->layer_link); |
| 3378 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3379 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 3380 | case SHELL_SURFACE_NONE: |
| 3381 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 3382 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3383 | ws = get_current_workspace(shell); |
| 3384 | wl_list_insert(&ws->layer.surface_list, &surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3385 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3386 | } |
| 3387 | |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 3388 | if (surface_type != SHELL_SURFACE_NONE) { |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 3389 | weston_surface_update_transform(surface); |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 3390 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 3391 | surface->output = shsurf->output; |
| 3392 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 3393 | |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 3394 | switch (surface_type) { |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 3395 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 3396 | if (shsurf->transient.flags == |
| 3397 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 3398 | break; |
| 3399 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 3400 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3401 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 3402 | if (!shell->locked) { |
| 3403 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 3404 | activate(shell, surface, seat); |
| 3405 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 3406 | break; |
| 3407 | default: |
| 3408 | break; |
| 3409 | } |
| 3410 | |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 3411 | if (surface_type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 3412 | { |
| 3413 | switch (shell->win_animation_type) { |
| 3414 | case ANIMATION_FADE: |
Ander Conselvan de Oliveira | ee41605 | 2013-02-21 18:35:17 +0200 | [diff] [blame] | 3415 | weston_fade_run(surface, 0.0, 1.0, 200.0, NULL, NULL); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 3416 | break; |
| 3417 | case ANIMATION_ZOOM: |
| 3418 | weston_zoom_run(surface, 0.8, 1.0, NULL, NULL); |
| 3419 | break; |
| 3420 | default: |
| 3421 | break; |
| 3422 | } |
| 3423 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3427 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3428 | float x, float y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 3429 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3430 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 3431 | struct shell_surface *shsurf; |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3432 | int32_t surf_x, surf_y; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 3433 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3434 | shsurf = get_shell_surface(surface); |
| 3435 | if (shsurf) |
| 3436 | surface_type = shsurf->type; |
| 3437 | |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 3438 | weston_surface_configure(surface, x, y, width, height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3439 | |
| 3440 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3441 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 3442 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3443 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3444 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3445 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3446 | /* setting x, y and using configure to change that geometry */ |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3447 | surface_subsurfaces_boundingbox(shsurf->surface, &surf_x, &surf_y, |
| 3448 | NULL, NULL); |
| 3449 | surface->geometry.x = surface->output->x - surf_x; |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 3450 | surface->geometry.y = surface->output->y + |
Giulio Camuffo | b836664 | 2013-04-25 13:57:46 +0300 | [diff] [blame] | 3451 | get_output_panel_height(shell,surface->output) - surf_y; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3452 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3453 | case SHELL_SURFACE_TOPLEVEL: |
| 3454 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 3455 | default: |
| 3456 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 3457 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 3458 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 3459 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 3460 | if (surface->output) { |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 3461 | weston_surface_update_transform(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3462 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3463 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 3464 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3465 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3466 | } |
| 3467 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3468 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3469 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3470 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 3471 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3472 | struct desktop_shell *shell = shsurf->shell; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3473 | |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 3474 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3475 | |
Giulio Camuffo | 5085a75 | 2013-03-25 21:42:45 +0100 | [diff] [blame] | 3476 | if (!weston_surface_is_mapped(es) && !wl_list_empty(&shsurf->popup.grab_link)) { |
| 3477 | remove_popup_grab(shsurf); |
| 3478 | } |
| 3479 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3480 | if (width == 0) |
| 3481 | return; |
| 3482 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3483 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 3484 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3485 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 3486 | type_changed = 1; |
| 3487 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 3488 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3489 | if (!weston_surface_is_mapped(es)) { |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3490 | map(shell, es, width, height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 3491 | } else if (type_changed || sx != 0 || sy != 0 || |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3492 | es->geometry.width != width || |
| 3493 | es->geometry.height != height) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 3494 | float from_x, from_y; |
| 3495 | float to_x, to_y; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3496 | |
| 3497 | weston_surface_to_global_float(es, 0, 0, &from_x, &from_y); |
| 3498 | weston_surface_to_global_float(es, sx, sy, &to_x, &to_y); |
| 3499 | configure(shell, es, |
| 3500 | es->geometry.x + to_x - from_x, |
| 3501 | es->geometry.y + to_y - from_y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3502 | width, height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 3503 | } |
| 3504 | } |
| 3505 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3506 | static void launch_desktop_shell_process(void *data); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3507 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3508 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3509 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3510 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3511 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3512 | struct desktop_shell *shell = |
| 3513 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3514 | |
| 3515 | shell->child.process.pid = 0; |
| 3516 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3517 | |
| 3518 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 3519 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 3520 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3521 | shell->child.deathstamp = time; |
| 3522 | shell->child.deathcount = 0; |
| 3523 | } |
| 3524 | |
| 3525 | shell->child.deathcount++; |
| 3526 | if (shell->child.deathcount > 5) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3527 | weston_log("weston-desktop-shell died, giving up.\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3528 | return; |
| 3529 | } |
| 3530 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 3531 | weston_log("weston-desktop-shell died, respawning...\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 3532 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 3533 | shell_fade_startup(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3534 | } |
| 3535 | |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3536 | static void |
| 3537 | launch_desktop_shell_process(void *data) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3538 | { |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3539 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 3540 | const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3541 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3542 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 3543 | &shell->child.process, |
| 3544 | shell_exe, |
| 3545 | desktop_shell_sigchld); |
| 3546 | |
| 3547 | if (!shell->child.client) |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 3548 | weston_log("not able to start %s\n", shell_exe); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3552 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 3553 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3554 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3555 | |
| 3556 | wl_client_add_object(client, &wl_shell_interface, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 3557 | &shell_implementation, id, shell); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3558 | } |
| 3559 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3560 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3561 | unbind_desktop_shell(struct wl_resource *resource) |
| 3562 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3563 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 3564 | |
| 3565 | if (shell->locked) |
| 3566 | resume_desktop(shell); |
| 3567 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3568 | shell->child.desktop_shell = NULL; |
| 3569 | shell->prepare_event_sent = false; |
| 3570 | free(resource); |
| 3571 | } |
| 3572 | |
| 3573 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3574 | bind_desktop_shell(struct wl_client *client, |
| 3575 | void *data, uint32_t version, uint32_t id) |
| 3576 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3577 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 3578 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3579 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 3580 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 3581 | &desktop_shell_implementation, |
| 3582 | id, shell); |
| 3583 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3584 | if (client == shell->child.client) { |
| 3585 | resource->destroy = unbind_desktop_shell; |
| 3586 | shell->child.desktop_shell = resource; |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 3587 | |
| 3588 | if (version < 2) |
| 3589 | shell_fade_startup(shell); |
| 3590 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 3591 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3592 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 3593 | |
| 3594 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3595 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3596 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3597 | } |
| 3598 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3599 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3600 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3601 | { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3602 | struct desktop_shell *shell = surface->configure_private; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3603 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3604 | if (width == 0) |
| 3605 | return; |
| 3606 | |
Pekka Paalanen | 3a1d07d | 2012-12-20 14:02:13 +0200 | [diff] [blame] | 3607 | /* XXX: starting weston-screensaver beforehand does not work */ |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3608 | if (!shell->locked) |
| 3609 | return; |
| 3610 | |
| 3611 | center_on_output(surface, surface->output); |
| 3612 | |
| 3613 | if (wl_list_empty(&surface->layer_link)) { |
| 3614 | wl_list_insert(shell->lock_layer.surface_list.prev, |
| 3615 | &surface->layer_link); |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 3616 | weston_surface_update_transform(surface); |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 3617 | wl_event_source_timer_update(shell->screensaver.timer, |
| 3618 | shell->screensaver.duration); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3619 | shell_fade(shell, FADE_IN); |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3620 | } |
| 3621 | } |
| 3622 | |
| 3623 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3624 | screensaver_set_surface(struct wl_client *client, |
| 3625 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3626 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3627 | struct wl_resource *output_resource) |
| 3628 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3629 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3630 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3631 | struct weston_output *output = output_resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3632 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 3633 | surface->configure = screensaver_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3634 | surface->configure_private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3635 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | static const struct screensaver_interface screensaver_implementation = { |
| 3639 | screensaver_set_surface |
| 3640 | }; |
| 3641 | |
| 3642 | static void |
| 3643 | unbind_screensaver(struct wl_resource *resource) |
| 3644 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3645 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3646 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3647 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3648 | free(resource); |
| 3649 | } |
| 3650 | |
| 3651 | static void |
| 3652 | bind_screensaver(struct wl_client *client, |
| 3653 | void *data, uint32_t version, uint32_t id) |
| 3654 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3655 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3656 | struct wl_resource *resource; |
| 3657 | |
| 3658 | resource = wl_client_add_object(client, &screensaver_interface, |
| 3659 | &screensaver_implementation, |
| 3660 | id, shell); |
| 3661 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3662 | if (shell->screensaver.binding == NULL) { |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3663 | resource->destroy = unbind_screensaver; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3664 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3665 | return; |
| 3666 | } |
| 3667 | |
| 3668 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3669 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3670 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3671 | } |
| 3672 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3673 | static void |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3674 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy, int32_t width, int32_t height) |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3675 | { |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3676 | struct input_panel_surface *ip_surface = surface->configure_private; |
| 3677 | struct desktop_shell *shell = ip_surface->shell; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 3678 | struct weston_mode *mode; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 3679 | float x, y; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3680 | uint32_t show_surface = 0; |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 3681 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3682 | if (width == 0) |
| 3683 | return; |
| 3684 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3685 | if (!weston_surface_is_mapped(surface)) { |
| 3686 | if (!shell->showing_input_panels) |
| 3687 | return; |
| 3688 | |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3689 | show_surface = 1; |
| 3690 | } |
Jan Arne Petersen | af7b6c9 | 2013-01-16 21:26:53 +0100 | [diff] [blame] | 3691 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 3692 | 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] | 3693 | |
| 3694 | if (ip_surface->panel) { |
| 3695 | x = shell->text_input.surface->geometry.x + shell->text_input.cursor_rectangle.x2; |
| 3696 | y = shell->text_input.surface->geometry.y + shell->text_input.cursor_rectangle.y2; |
| 3697 | } else { |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 3698 | mode = ip_surface->output->current; |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3699 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 3700 | x = ip_surface->output->x + (mode->width - width) / 2; |
| 3701 | y = ip_surface->output->y + mode->height - height; |
| 3702 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3703 | |
| 3704 | weston_surface_configure(surface, |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3705 | x, y, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3706 | width, height); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3707 | |
| 3708 | if (show_surface) { |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 3709 | wl_list_insert(&shell->input_panel_layer.surface_list, |
| 3710 | &surface->layer_link); |
| 3711 | weston_surface_update_transform(surface); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3712 | weston_surface_damage(surface); |
| 3713 | weston_slide_run(surface, surface->geometry.height, 0, NULL, NULL); |
| 3714 | } |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | static void |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3718 | destroy_input_panel_surface(struct input_panel_surface *input_panel_surface) |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3719 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3720 | wl_list_remove(&input_panel_surface->surface_destroy_listener.link); |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3721 | wl_list_remove(&input_panel_surface->link); |
| 3722 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3723 | input_panel_surface->surface->configure = NULL; |
| 3724 | |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3725 | free(input_panel_surface); |
| 3726 | } |
| 3727 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3728 | static struct input_panel_surface * |
| 3729 | get_input_panel_surface(struct weston_surface *surface) |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3730 | { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3731 | if (surface->configure == input_panel_configure) { |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3732 | return surface->configure_private; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3733 | } else { |
| 3734 | return NULL; |
| 3735 | } |
| 3736 | } |
| 3737 | |
| 3738 | static void |
| 3739 | input_panel_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3740 | { |
| 3741 | struct input_panel_surface *ipsurface = container_of(listener, |
| 3742 | struct input_panel_surface, |
| 3743 | surface_destroy_listener); |
| 3744 | |
| 3745 | if (ipsurface->resource.client) { |
| 3746 | wl_resource_destroy(&ipsurface->resource); |
| 3747 | } else { |
| 3748 | wl_signal_emit(&ipsurface->resource.destroy_signal, |
| 3749 | &ipsurface->resource); |
| 3750 | destroy_input_panel_surface(ipsurface); |
| 3751 | } |
| 3752 | } |
| 3753 | static struct input_panel_surface * |
| 3754 | create_input_panel_surface(struct desktop_shell *shell, |
| 3755 | struct weston_surface *surface) |
| 3756 | { |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3757 | struct input_panel_surface *input_panel_surface; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3758 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3759 | input_panel_surface = calloc(1, sizeof *input_panel_surface); |
| 3760 | if (!input_panel_surface) |
| 3761 | return NULL; |
| 3762 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 3763 | surface->configure = input_panel_configure; |
Giulio Camuffo | 7fe01b1 | 2013-03-28 18:02:42 +0100 | [diff] [blame] | 3764 | surface->configure_private = input_panel_surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3765 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3766 | input_panel_surface->shell = shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3767 | |
| 3768 | input_panel_surface->surface = surface; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3769 | |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3770 | wl_signal_init(&input_panel_surface->resource.destroy_signal); |
| 3771 | input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy; |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 3772 | wl_signal_add(&surface->resource.destroy_signal, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3773 | &input_panel_surface->surface_destroy_listener); |
| 3774 | |
| 3775 | wl_list_init(&input_panel_surface->link); |
| 3776 | |
| 3777 | return input_panel_surface; |
| 3778 | } |
| 3779 | |
| 3780 | static void |
| 3781 | input_panel_surface_set_toplevel(struct wl_client *client, |
| 3782 | struct wl_resource *resource, |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 3783 | struct wl_resource *output_resource, |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3784 | uint32_t position) |
| 3785 | { |
| 3786 | struct input_panel_surface *input_panel_surface = resource->data; |
| 3787 | struct desktop_shell *shell = input_panel_surface->shell; |
Philipp Brüschweiler | 8801357 | 2012-08-06 13:44:42 +0200 | [diff] [blame] | 3788 | |
| 3789 | wl_list_insert(&shell->input_panel.surfaces, |
| 3790 | &input_panel_surface->link); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3791 | |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 3792 | input_panel_surface->output = output_resource->data; |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3793 | input_panel_surface->panel = 0; |
Jan Arne Petersen | 7cd29e1 | 2013-04-18 16:47:29 +0200 | [diff] [blame] | 3794 | |
| 3795 | fprintf(stderr, "%s panel: %d, output: %p\n", __FUNCTION__, |
| 3796 | input_panel_surface->panel, |
| 3797 | input_panel_surface->output); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | static void |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 3801 | input_panel_surface_set_overlay_panel(struct wl_client *client, |
| 3802 | struct wl_resource *resource) |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 3803 | { |
| 3804 | struct input_panel_surface *input_panel_surface = resource->data; |
| 3805 | struct desktop_shell *shell = input_panel_surface->shell; |
| 3806 | |
| 3807 | wl_list_insert(&shell->input_panel.surfaces, |
| 3808 | &input_panel_surface->link); |
| 3809 | |
| 3810 | input_panel_surface->panel = 1; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3811 | } |
| 3812 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 3813 | 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] | 3814 | input_panel_surface_set_toplevel, |
Jan Arne Petersen | 70d942b | 2013-04-18 16:47:37 +0200 | [diff] [blame] | 3815 | input_panel_surface_set_overlay_panel |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3816 | }; |
| 3817 | |
| 3818 | static void |
| 3819 | destroy_input_panel_surface_resource(struct wl_resource *resource) |
| 3820 | { |
| 3821 | struct input_panel_surface *ipsurf = resource->data; |
| 3822 | |
| 3823 | destroy_input_panel_surface(ipsurf); |
| 3824 | } |
| 3825 | |
| 3826 | static void |
| 3827 | input_panel_get_input_panel_surface(struct wl_client *client, |
| 3828 | struct wl_resource *resource, |
| 3829 | uint32_t id, |
| 3830 | struct wl_resource *surface_resource) |
| 3831 | { |
| 3832 | struct weston_surface *surface = surface_resource->data; |
| 3833 | struct desktop_shell *shell = resource->data; |
| 3834 | struct input_panel_surface *ipsurf; |
| 3835 | |
| 3836 | if (get_input_panel_surface(surface)) { |
| 3837 | wl_resource_post_error(surface_resource, |
| 3838 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 3839 | "wl_input_panel::get_input_panel_surface already requested"); |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3840 | return; |
| 3841 | } |
| 3842 | |
| 3843 | ipsurf = create_input_panel_surface(shell, surface); |
| 3844 | if (!ipsurf) { |
| 3845 | wl_resource_post_error(surface_resource, |
| 3846 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3847 | "surface->configure already set"); |
| 3848 | return; |
| 3849 | } |
| 3850 | |
| 3851 | ipsurf->resource.destroy = destroy_input_panel_surface_resource; |
| 3852 | ipsurf->resource.object.id = id; |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 3853 | ipsurf->resource.object.interface = &wl_input_panel_surface_interface; |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3854 | ipsurf->resource.object.implementation = |
| 3855 | (void (**)(void)) &input_panel_surface_implementation; |
| 3856 | ipsurf->resource.data = ipsurf; |
| 3857 | |
| 3858 | wl_client_add_resource(client, &ipsurf->resource); |
| 3859 | } |
| 3860 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 3861 | static const struct wl_input_panel_interface input_panel_implementation = { |
Jan Arne Petersen | ffbb20f | 2013-01-16 21:26:55 +0100 | [diff] [blame] | 3862 | input_panel_get_input_panel_surface |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3863 | }; |
| 3864 | |
| 3865 | static void |
| 3866 | unbind_input_panel(struct wl_resource *resource) |
| 3867 | { |
| 3868 | struct desktop_shell *shell = resource->data; |
| 3869 | |
| 3870 | shell->input_panel.binding = NULL; |
| 3871 | free(resource); |
| 3872 | } |
| 3873 | |
| 3874 | static void |
| 3875 | bind_input_panel(struct wl_client *client, |
| 3876 | void *data, uint32_t version, uint32_t id) |
| 3877 | { |
| 3878 | struct desktop_shell *shell = data; |
| 3879 | struct wl_resource *resource; |
| 3880 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 3881 | resource = wl_client_add_object(client, &wl_input_panel_interface, |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3882 | &input_panel_implementation, |
| 3883 | id, shell); |
| 3884 | |
| 3885 | if (shell->input_panel.binding == NULL) { |
| 3886 | resource->destroy = unbind_input_panel; |
| 3887 | shell->input_panel.binding = resource; |
| 3888 | return; |
| 3889 | } |
| 3890 | |
| 3891 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 3892 | "interface object already bound"); |
| 3893 | wl_resource_destroy(resource); |
| 3894 | } |
| 3895 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3896 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3897 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3898 | struct weston_surface *current; |
| 3899 | struct wl_listener listener; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 3900 | struct weston_keyboard_grab grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3901 | }; |
| 3902 | |
| 3903 | static void |
| 3904 | switcher_next(struct switcher *switcher) |
| 3905 | { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3906 | struct weston_surface *surface; |
| 3907 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 3908 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3909 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3910 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3911 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3912 | switch (get_shell_surface_type(surface)) { |
| 3913 | case SHELL_SURFACE_TOPLEVEL: |
| 3914 | case SHELL_SURFACE_FULLSCREEN: |
| 3915 | case SHELL_SURFACE_MAXIMIZED: |
| 3916 | if (first == NULL) |
| 3917 | first = surface; |
| 3918 | if (prev == switcher->current) |
| 3919 | next = surface; |
| 3920 | prev = surface; |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 3921 | surface->alpha = 0.25; |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 3922 | weston_surface_geometry_dirty(surface); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3923 | weston_surface_damage(surface); |
| 3924 | break; |
| 3925 | default: |
| 3926 | break; |
| 3927 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 3928 | |
| 3929 | if (is_black_surface(surface, NULL)) { |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 3930 | surface->alpha = 0.25; |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 3931 | weston_surface_geometry_dirty(surface); |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 3932 | weston_surface_damage(surface); |
| 3933 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | if (next == NULL) |
| 3937 | next = first; |
| 3938 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 3939 | if (next == NULL) |
| 3940 | return; |
| 3941 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3942 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 3943 | wl_signal_add(&next->resource.destroy_signal, &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3944 | |
| 3945 | switcher->current = next; |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3946 | next->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 3947 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 3948 | shsurf = get_shell_surface(switcher->current); |
| 3949 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3950 | shsurf->fullscreen.black_surface->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3954 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3955 | { |
| 3956 | struct switcher *switcher = |
| 3957 | container_of(listener, struct switcher, listener); |
| 3958 | |
| 3959 | switcher_next(switcher); |
| 3960 | } |
| 3961 | |
| 3962 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3963 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3964 | { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3965 | struct weston_surface *surface; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 3966 | struct weston_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3967 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3968 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3969 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3970 | surface->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3971 | weston_surface_damage(surface); |
| 3972 | } |
| 3973 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 3974 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3975 | activate(switcher->shell, switcher->current, |
| 3976 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3977 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 3978 | weston_keyboard_end_grab(keyboard); |
| 3979 | if (keyboard->input_method_resource) |
| 3980 | keyboard->grab = &keyboard->input_method_grab; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3981 | free(switcher); |
| 3982 | } |
| 3983 | |
| 3984 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 3985 | switcher_key(struct weston_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3986 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3987 | { |
| 3988 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3989 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3990 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3991 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3992 | switcher_next(switcher); |
| 3993 | } |
| 3994 | |
| 3995 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 3996 | switcher_modifier(struct weston_keyboard_grab *grab, uint32_t serial, |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3997 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3998 | uint32_t mods_locked, uint32_t group) |
| 3999 | { |
| 4000 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 4001 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4002 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4003 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 4004 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 4005 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4006 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4007 | static const struct weston_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 4008 | switcher_key, |
| 4009 | switcher_modifier, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4010 | }; |
| 4011 | |
| 4012 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4013 | switcher_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4014 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4015 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4016 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4017 | struct switcher *switcher; |
| 4018 | |
| 4019 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4020 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4021 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 4022 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4023 | wl_list_init(&switcher->listener.link); |
| 4024 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 4025 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4026 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4027 | weston_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 4028 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 4029 | switcher_next(switcher); |
| 4030 | } |
| 4031 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4032 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4033 | backlight_binding(struct weston_seat *seat, uint32_t time, uint32_t key, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4034 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4035 | { |
| 4036 | struct weston_compositor *compositor = data; |
| 4037 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4038 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4039 | |
| 4040 | /* TODO: we're limiting to simple use cases, where we assume just |
| 4041 | * control on the primary display. We'd have to extend later if we |
| 4042 | * ever get support for setting backlights on random desktop LCD |
| 4043 | * panels though */ |
| 4044 | output = get_default_output(compositor); |
| 4045 | if (!output) |
| 4046 | return; |
| 4047 | |
| 4048 | if (!output->set_backlight) |
| 4049 | return; |
| 4050 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4051 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 4052 | backlight_new = output->backlight_current - 25; |
| 4053 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 4054 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4055 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 4056 | if (backlight_new < 5) |
| 4057 | backlight_new = 5; |
| 4058 | if (backlight_new > 255) |
| 4059 | backlight_new = 255; |
| 4060 | |
| 4061 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4062 | output->set_backlight(output, output->backlight_current); |
| 4063 | } |
| 4064 | |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4065 | struct debug_binding_grab { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4066 | struct weston_keyboard_grab grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4067 | struct weston_seat *seat; |
| 4068 | uint32_t key[2]; |
| 4069 | int key_released[2]; |
| 4070 | }; |
| 4071 | |
| 4072 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4073 | 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] | 4074 | uint32_t key, uint32_t state) |
| 4075 | { |
| 4076 | struct debug_binding_grab *db = (struct debug_binding_grab *) grab; |
| 4077 | struct wl_resource *resource; |
| 4078 | struct wl_display *display; |
| 4079 | uint32_t serial; |
| 4080 | int send = 0, terminate = 0; |
| 4081 | int check_binding = 1; |
| 4082 | int i; |
| 4083 | |
| 4084 | if (state == WL_KEYBOARD_KEY_STATE_RELEASED) { |
| 4085 | /* Do not run bindings on key releases */ |
| 4086 | check_binding = 0; |
| 4087 | |
| 4088 | for (i = 0; i < 2; i++) |
| 4089 | if (key == db->key[i]) |
| 4090 | db->key_released[i] = 1; |
| 4091 | |
| 4092 | if (db->key_released[0] && db->key_released[1]) { |
| 4093 | /* All key releases been swalled so end the grab */ |
| 4094 | terminate = 1; |
| 4095 | } else if (key != db->key[0] && key != db->key[1]) { |
| 4096 | /* Should not swallow release of other keys */ |
| 4097 | send = 1; |
| 4098 | } |
| 4099 | } else if (key == db->key[0] && !db->key_released[0]) { |
| 4100 | /* Do not check bindings for the first press of the binding |
| 4101 | * key. This allows it to be used as a debug shortcut. |
| 4102 | * We still need to swallow this event. */ |
| 4103 | check_binding = 0; |
| 4104 | } else if (db->key[1]) { |
| 4105 | /* If we already ran a binding don't process another one since |
| 4106 | * we can't keep track of all the binding keys that were |
| 4107 | * pressed in order to swallow the release events. */ |
| 4108 | send = 1; |
| 4109 | check_binding = 0; |
| 4110 | } |
| 4111 | |
| 4112 | if (check_binding) { |
| 4113 | struct weston_compositor *ec = db->seat->compositor; |
| 4114 | |
| 4115 | if (weston_compositor_run_debug_binding(ec, db->seat, time, |
| 4116 | key, state)) { |
| 4117 | /* We ran a binding so swallow the press and keep the |
| 4118 | * grab to swallow the released too. */ |
| 4119 | send = 0; |
| 4120 | terminate = 0; |
| 4121 | db->key[1] = key; |
| 4122 | } else { |
| 4123 | /* Terminate the grab since the key pressed is not a |
| 4124 | * debug binding key. */ |
| 4125 | send = 1; |
| 4126 | terminate = 1; |
| 4127 | } |
| 4128 | } |
| 4129 | |
| 4130 | if (send) { |
| 4131 | resource = grab->keyboard->focus_resource; |
| 4132 | |
| 4133 | if (resource) { |
| 4134 | display = wl_client_get_display(resource->client); |
| 4135 | serial = wl_display_next_serial(display); |
| 4136 | wl_keyboard_send_key(resource, serial, time, key, state); |
| 4137 | } |
| 4138 | } |
| 4139 | |
| 4140 | if (terminate) { |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4141 | weston_keyboard_end_grab(grab->keyboard); |
| 4142 | if (grab->keyboard->input_method_resource) |
| 4143 | grab->keyboard->grab = &grab->keyboard->input_method_grab; |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4144 | free(db); |
| 4145 | } |
| 4146 | } |
| 4147 | |
| 4148 | static void |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4149 | 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] | 4150 | uint32_t mods_depressed, uint32_t mods_latched, |
| 4151 | uint32_t mods_locked, uint32_t group) |
| 4152 | { |
| 4153 | struct wl_resource *resource; |
| 4154 | |
| 4155 | resource = grab->keyboard->focus_resource; |
| 4156 | if (!resource) |
| 4157 | return; |
| 4158 | |
| 4159 | wl_keyboard_send_modifiers(resource, serial, mods_depressed, |
| 4160 | mods_latched, mods_locked, group); |
| 4161 | } |
| 4162 | |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4163 | struct weston_keyboard_grab_interface debug_binding_keyboard_grab = { |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4164 | debug_binding_key, |
| 4165 | debug_binding_modifiers |
| 4166 | }; |
| 4167 | |
| 4168 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4169 | 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] | 4170 | { |
| 4171 | struct debug_binding_grab *grab; |
| 4172 | |
| 4173 | grab = calloc(1, sizeof *grab); |
| 4174 | if (!grab) |
| 4175 | return; |
| 4176 | |
| 4177 | grab->seat = (struct weston_seat *) seat; |
| 4178 | grab->key[0] = key; |
| 4179 | grab->grab.interface = &debug_binding_keyboard_grab; |
Kristian Høgsberg | 29139d4 | 2013-04-18 15:25:39 -0400 | [diff] [blame] | 4180 | weston_keyboard_start_grab(seat->keyboard, &grab->grab); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4181 | } |
| 4182 | |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 4183 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4184 | 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] | 4185 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4186 | { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 4187 | struct weston_surface *focus_surface; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4188 | struct wl_client *client; |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4189 | struct desktop_shell *shell = data; |
| 4190 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4191 | pid_t pid; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4192 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 4193 | focus_surface = seat->keyboard->focus; |
| 4194 | if (!focus_surface) |
| 4195 | return; |
| 4196 | |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4197 | wl_signal_emit(&compositor->kill_signal, focus_surface); |
| 4198 | |
Philipp Brüschweiler | 6cef009 | 2012-08-13 21:27:27 +0200 | [diff] [blame] | 4199 | client = focus_surface->resource.client; |
Tiago Vignatti | 920f197 | 2012-09-27 17:48:35 +0300 | [diff] [blame] | 4200 | wl_client_get_credentials(client, &pid, NULL, NULL); |
| 4201 | |
| 4202 | /* Skip clients that we launched ourselves (the credentials of |
| 4203 | * the socketpair is ours) */ |
| 4204 | if (pid == getpid()) |
| 4205 | return; |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4206 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4207 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4211 | workspace_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4212 | uint32_t key, void *data) |
| 4213 | { |
| 4214 | struct desktop_shell *shell = data; |
| 4215 | unsigned int new_index = shell->workspaces.current; |
| 4216 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4217 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4218 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4219 | if (new_index != 0) |
| 4220 | new_index--; |
| 4221 | |
| 4222 | change_workspace(shell, new_index); |
| 4223 | } |
| 4224 | |
| 4225 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4226 | workspace_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4227 | uint32_t key, void *data) |
| 4228 | { |
| 4229 | struct desktop_shell *shell = data; |
| 4230 | unsigned int new_index = shell->workspaces.current; |
| 4231 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4232 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4233 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4234 | if (new_index < shell->workspaces.num - 1) |
| 4235 | new_index++; |
| 4236 | |
| 4237 | change_workspace(shell, new_index); |
| 4238 | } |
| 4239 | |
| 4240 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4241 | workspace_f_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4242 | uint32_t key, void *data) |
| 4243 | { |
| 4244 | struct desktop_shell *shell = data; |
| 4245 | unsigned int new_index; |
| 4246 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 4247 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 4248 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4249 | new_index = key - KEY_F1; |
| 4250 | if (new_index >= shell->workspaces.num) |
| 4251 | new_index = shell->workspaces.num - 1; |
| 4252 | |
| 4253 | change_workspace(shell, new_index); |
| 4254 | } |
| 4255 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4256 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4257 | workspace_move_surface_up_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4258 | uint32_t key, void *data) |
| 4259 | { |
| 4260 | struct desktop_shell *shell = data; |
| 4261 | unsigned int new_index = shell->workspaces.current; |
| 4262 | |
| 4263 | if (shell->locked) |
| 4264 | return; |
| 4265 | |
| 4266 | if (new_index != 0) |
| 4267 | new_index--; |
| 4268 | |
| 4269 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 4270 | } |
| 4271 | |
| 4272 | static void |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 4273 | workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time, |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4274 | uint32_t key, void *data) |
| 4275 | { |
| 4276 | struct desktop_shell *shell = data; |
| 4277 | unsigned int new_index = shell->workspaces.current; |
| 4278 | |
| 4279 | if (shell->locked) |
| 4280 | return; |
| 4281 | |
| 4282 | if (new_index < shell->workspaces.num - 1) |
| 4283 | new_index++; |
| 4284 | |
| 4285 | take_surface_to_workspace_by_seat(shell, seat, new_index); |
| 4286 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4287 | |
| 4288 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4289 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4290 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4291 | struct desktop_shell *shell = |
| 4292 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4293 | struct workspace **ws; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4294 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 4295 | if (shell->child.client) |
| 4296 | wl_client_destroy(shell->child.client); |
| 4297 | |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4298 | wl_list_remove(&shell->idle_listener.link); |
| 4299 | wl_list_remove(&shell->wake_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4300 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 4301 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 4302 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4303 | wl_array_for_each(ws, &shell->workspaces.array) |
| 4304 | workspace_destroy(*ws); |
| 4305 | wl_array_release(&shell->workspaces.array); |
| 4306 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4307 | free(shell->screensaver.path); |
| 4308 | free(shell); |
| 4309 | } |
| 4310 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4311 | static void |
| 4312 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 4313 | { |
| 4314 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4315 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4316 | |
| 4317 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4318 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 4319 | MODIFIER_CTRL | MODIFIER_ALT, |
| 4320 | terminate_binding, ec); |
| 4321 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 4322 | click_to_activate_binding, |
| 4323 | shell); |
| 4324 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 4325 | MODIFIER_SUPER | MODIFIER_ALT, |
| 4326 | surface_opacity_binding, NULL); |
| 4327 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 4328 | MODIFIER_SUPER, zoom_axis_binding, |
| 4329 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4330 | |
| 4331 | /* configurable bindings */ |
| 4332 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4333 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 4334 | zoom_key_binding, NULL); |
| 4335 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 4336 | zoom_key_binding, NULL); |
| 4337 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 4338 | shell); |
| 4339 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 4340 | resize_binding, shell); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4341 | |
| 4342 | if (ec->capabilities & WESTON_CAP_ROTATION_ANY) |
| 4343 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 4344 | rotate_binding, NULL); |
| 4345 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4346 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 4347 | shell); |
| 4348 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 4349 | ec); |
| 4350 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 4351 | backlight_binding, ec); |
| 4352 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 4353 | ec); |
| 4354 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 4355 | backlight_binding, ec); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4356 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 4357 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4358 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 4359 | workspace_up_binding, shell); |
| 4360 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 4361 | workspace_down_binding, shell); |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4362 | weston_compositor_add_key_binding(ec, KEY_UP, mod | MODIFIER_SHIFT, |
| 4363 | workspace_move_surface_up_binding, |
| 4364 | shell); |
| 4365 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod | MODIFIER_SHIFT, |
| 4366 | workspace_move_surface_down_binding, |
| 4367 | shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4368 | |
| 4369 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 4370 | if (shell->workspaces.num > 1) { |
| 4371 | num_workspace_bindings = shell->workspaces.num; |
| 4372 | if (num_workspace_bindings > 6) |
| 4373 | num_workspace_bindings = 6; |
| 4374 | for (i = 0; i < num_workspace_bindings; i++) |
| 4375 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 4376 | workspace_f_binding, |
| 4377 | shell); |
| 4378 | } |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4379 | |
| 4380 | /* Debug bindings */ |
| 4381 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
| 4382 | debug_binding, shell); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4383 | } |
| 4384 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4385 | WL_EXPORT int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 4386 | module_init(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4387 | int *argc, char *argv[]) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4388 | { |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 4389 | struct weston_seat *seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 4390 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4391 | struct workspace **pws; |
| 4392 | unsigned int i; |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4393 | struct wl_event_loop *loop; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4394 | |
| 4395 | shell = malloc(sizeof *shell); |
| 4396 | if (shell == NULL) |
| 4397 | return -1; |
| 4398 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 4399 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4400 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4401 | |
| 4402 | shell->destroy_listener.notify = shell_destroy; |
| 4403 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4404 | shell->idle_listener.notify = idle_handler; |
| 4405 | wl_signal_add(&ec->idle_signal, &shell->idle_listener); |
| 4406 | shell->wake_listener.notify = wake_handler; |
| 4407 | wl_signal_add(&ec->wake_signal, &shell->wake_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4408 | shell->show_input_panel_listener.notify = show_input_panels; |
| 4409 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 4410 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 4411 | 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] | 4412 | shell->update_input_panel_listener.notify = update_input_panels; |
| 4413 | 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] | 4414 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 4415 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 4416 | ec->shell_interface.create_shell_surface = create_shell_surface; |
| 4417 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 4418 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | b810eb5 | 2013-02-12 20:07:05 -0500 | [diff] [blame] | 4419 | ec->shell_interface.set_fullscreen = set_fullscreen; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 4420 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 4421 | ec->shell_interface.resize = surface_resize; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4422 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4423 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 4424 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4425 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 4426 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4427 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 4428 | weston_layer_init(&shell->lock_layer, NULL); |
Philipp Brüschweiler | 711fda8 | 2012-08-09 18:50:43 +0200 | [diff] [blame] | 4429 | weston_layer_init(&shell->input_panel_layer, NULL); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4430 | |
| 4431 | wl_array_init(&shell->workspaces.array); |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 4432 | wl_list_init(&shell->workspaces.client_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 4433 | |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4434 | shell_configuration(shell, ec->config_fd); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 4435 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 4436 | for (i = 0; i < shell->workspaces.num; i++) { |
| 4437 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 4438 | if (pws == NULL) |
| 4439 | return -1; |
| 4440 | |
| 4441 | *pws = workspace_create(); |
| 4442 | if (*pws == NULL) |
| 4443 | return -1; |
| 4444 | } |
| 4445 | activate_workspace(shell, 0); |
| 4446 | |
Jonas Ådahl | 8de6a1d | 2012-08-29 22:13:00 +0200 | [diff] [blame] | 4447 | wl_list_init(&shell->workspaces.anim_sticky_list); |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 4448 | wl_list_init(&shell->workspaces.animation.link); |
| 4449 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 4450 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4451 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 4452 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4453 | return -1; |
| 4454 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 4455 | if (wl_display_add_global(ec->wl_display, |
| 4456 | &desktop_shell_interface, |
| 4457 | shell, bind_desktop_shell) == NULL) |
| 4458 | return -1; |
| 4459 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 4460 | if (wl_display_add_global(ec->wl_display, &screensaver_interface, |
| 4461 | shell, bind_screensaver) == NULL) |
| 4462 | return -1; |
| 4463 | |
Jan Arne Petersen | cc75ec1 | 2013-04-18 16:47:39 +0200 | [diff] [blame] | 4464 | if (wl_display_add_global(ec->wl_display, &wl_input_panel_interface, |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4465 | shell, bind_input_panel) == NULL) |
| 4466 | return -1; |
| 4467 | |
Jonas Ådahl | e9d2250 | 2012-08-29 22:13:01 +0200 | [diff] [blame] | 4468 | if (wl_display_add_global(ec->wl_display, &workspace_manager_interface, |
| 4469 | shell, bind_workspace_manager) == NULL) |
| 4470 | return -1; |
| 4471 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 4472 | shell->child.deathstamp = weston_compositor_get_time(); |
Tiago Vignatti | b7dbbd6 | 2012-09-25 17:57:01 +0300 | [diff] [blame] | 4473 | |
| 4474 | loop = wl_display_get_event_loop(ec->wl_display); |
| 4475 | wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 4476 | |
Ander Conselvan de Oliveira | 859e885 | 2013-02-21 18:35:21 +0200 | [diff] [blame] | 4477 | shell->screensaver.timer = |
| 4478 | wl_event_loop_add_timer(loop, screensaver_timeout, shell); |
| 4479 | |
Kristian Høgsberg | f4d2f23 | 2012-08-10 10:05:39 -0400 | [diff] [blame] | 4480 | wl_list_for_each(seat, &ec->seat_list, link) |
| 4481 | create_pointer_focus_listener(seat); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 4482 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 4483 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 4484 | |
Pekka Paalanen | 79346ab | 2013-05-22 18:03:09 +0300 | [diff] [blame^] | 4485 | shell_fade_init(shell); |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4486 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 4487 | return 0; |
| 4488 | } |