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 | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 33 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 34 | #include <wayland-server.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 35 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 36 | #include "desktop-shell-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 37 | #include "../shared/config-parser.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 39 | struct shell_surface; |
| 40 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 41 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 42 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 43 | |
| 44 | struct wl_listener lock_listener; |
| 45 | struct wl_listener unlock_listener; |
| 46 | struct wl_listener destroy_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 47 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 48 | struct weston_layer fullscreen_layer; |
| 49 | struct weston_layer panel_layer; |
| 50 | struct weston_layer toplevel_layer; |
| 51 | struct weston_layer background_layer; |
| 52 | struct weston_layer lock_layer; |
| 53 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 54 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 55 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 56 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 57 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 58 | |
| 59 | unsigned deathcount; |
| 60 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 61 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 62 | |
| 63 | bool locked; |
| 64 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 65 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 66 | struct shell_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 67 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 68 | |
| 69 | struct wl_list backgrounds; |
| 70 | struct wl_list panels; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 71 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 72 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 73 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 74 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 75 | struct wl_resource *binding; |
| 76 | struct wl_list surfaces; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 77 | struct weston_process process; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 78 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 79 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame^] | 80 | uint32_t binding_modifier; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 81 | struct weston_surface *debug_repaint_surface; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 82 | }; |
| 83 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 84 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 85 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 86 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 87 | SHELL_SURFACE_PANEL, |
| 88 | SHELL_SURFACE_BACKGROUND, |
| 89 | SHELL_SURFACE_LOCK, |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 90 | SHELL_SURFACE_SCREENSAVER, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 91 | |
| 92 | SHELL_SURFACE_TOPLEVEL, |
| 93 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 94 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 95 | SHELL_SURFACE_MAXIMIZED, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 96 | SHELL_SURFACE_POPUP |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 97 | }; |
| 98 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 99 | struct ping_timer { |
| 100 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 101 | uint32_t serial; |
| 102 | }; |
| 103 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 104 | struct shell_surface { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 105 | struct wl_resource resource; |
| 106 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 107 | struct weston_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 108 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 109 | struct shell_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 110 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 111 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 112 | enum shell_surface_type type; |
| 113 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 114 | bool saved_position_valid; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 115 | int unresponsive; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 116 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 117 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 118 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 119 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 120 | } rotation; |
| 121 | |
| 122 | struct { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 123 | struct wl_pointer_grab grab; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 124 | int32_t x, y; |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 125 | struct weston_transform parent_transform; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 126 | int32_t initial_up; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 127 | struct wl_input_device *device; |
| 128 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 129 | } popup; |
| 130 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 131 | struct { |
| 132 | enum wl_shell_surface_fullscreen_method type; |
| 133 | struct weston_transform transform; /* matrix from x, y */ |
| 134 | uint32_t framerate; |
| 135 | struct weston_surface *black_surface; |
| 136 | } fullscreen; |
| 137 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 138 | struct ping_timer *ping_timer; |
| 139 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 140 | struct { |
| 141 | struct weston_animation current; |
| 142 | int exists; |
| 143 | int fading_in; |
| 144 | uint32_t timestamp; |
| 145 | } unresponsive_animation; |
| 146 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 147 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 148 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 149 | struct wl_list link; |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 150 | |
| 151 | int force_configure; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 152 | }; |
| 153 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 154 | struct shell_grab { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 155 | struct wl_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 156 | struct shell_surface *shsurf; |
| 157 | struct wl_listener shsurf_destroy_listener; |
| 158 | }; |
| 159 | |
| 160 | struct weston_move_grab { |
| 161 | struct shell_grab base; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 162 | int32_t dx, dy; |
| 163 | }; |
| 164 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 165 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 166 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 167 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 168 | struct { |
| 169 | int32_t x; |
| 170 | int32_t y; |
| 171 | } center; |
| 172 | }; |
| 173 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 174 | static struct shell_surface * |
| 175 | get_shell_surface(struct weston_surface *surface); |
| 176 | |
| 177 | static struct desktop_shell * |
| 178 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 179 | |
| 180 | static bool |
| 181 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 182 | { |
| 183 | struct desktop_shell *shell; |
| 184 | struct weston_surface *top_fs_es; |
| 185 | |
| 186 | shell = shell_surface_get_shell(shsurf); |
| 187 | |
| 188 | if (wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 189 | return false; |
| 190 | |
| 191 | top_fs_es = container_of(shell->fullscreen_layer.surface_list.next, |
| 192 | struct weston_surface, |
| 193 | layer_link); |
| 194 | return (shsurf == get_shell_surface(top_fs_es)); |
| 195 | } |
| 196 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 197 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 198 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 199 | { |
| 200 | struct shell_grab *grab; |
| 201 | |
| 202 | grab = container_of(listener, struct shell_grab, |
| 203 | shsurf_destroy_listener); |
| 204 | |
| 205 | grab->shsurf = NULL; |
| 206 | } |
| 207 | |
| 208 | static void |
| 209 | shell_grab_init(struct shell_grab *grab, |
| 210 | const struct wl_pointer_grab_interface *interface, |
| 211 | struct shell_surface *shsurf) |
| 212 | { |
| 213 | grab->grab.interface = interface; |
| 214 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 215 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 216 | wl_signal_add(&shsurf->resource.destroy_signal, |
| 217 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 218 | |
| 219 | } |
| 220 | |
| 221 | static void |
| 222 | shell_grab_finish(struct shell_grab *grab) |
| 223 | { |
| 224 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
| 225 | } |
| 226 | |
| 227 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 228 | center_on_output(struct weston_surface *surface, |
| 229 | struct weston_output *output); |
| 230 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame^] | 231 | static uint32_t |
| 232 | get_modifier(char *modifier) |
| 233 | { |
| 234 | if (!modifier) |
| 235 | return MODIFIER_SUPER; |
| 236 | |
| 237 | if (!strcmp("ctrl", modifier)) |
| 238 | return MODIFIER_CTRL; |
| 239 | else if (!strcmp("alt", modifier)) |
| 240 | return MODIFIER_ALT; |
| 241 | else if (!strcmp("super", modifier)) |
| 242 | return MODIFIER_SUPER; |
| 243 | else |
| 244 | return MODIFIER_SUPER; |
| 245 | } |
| 246 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 247 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 248 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 249 | { |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 250 | char *config_file; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 251 | char *path = NULL; |
| 252 | int duration = 60; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame^] | 253 | char *modifier = NULL; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 254 | |
| 255 | struct config_key saver_keys[] = { |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 256 | { "path", CONFIG_KEY_STRING, &path }, |
| 257 | { "duration", CONFIG_KEY_INTEGER, &duration }, |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame^] | 258 | { "binding-modifier", CONFIG_KEY_STRING, &modifier }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 259 | }; |
| 260 | |
| 261 | struct config_section cs[] = { |
| 262 | { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL }, |
| 263 | }; |
| 264 | |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 265 | config_file = config_file_path("weston.ini"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 266 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 267 | free(config_file); |
| 268 | |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 269 | shell->screensaver.path = path; |
| 270 | shell->screensaver.duration = duration; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame^] | 271 | shell->binding_modifier = get_modifier(modifier); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 274 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 275 | noop_grab_focus(struct wl_pointer_grab *grab, |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 276 | struct wl_surface *surface, int32_t x, int32_t y) |
| 277 | { |
| 278 | grab->focus = NULL; |
| 279 | } |
| 280 | |
| 281 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 282 | move_grab_motion(struct wl_pointer_grab *grab, |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 283 | uint32_t time, int32_t x, int32_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 284 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 285 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 286 | struct wl_input_device *device = grab->input_device; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 287 | struct shell_surface *shsurf = move->base.shsurf; |
| 288 | struct weston_surface *es; |
| 289 | |
| 290 | if (!shsurf) |
| 291 | return; |
| 292 | |
| 293 | es = shsurf->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 294 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 295 | weston_surface_configure(es, |
| 296 | device->x + move->dx, |
| 297 | device->y + move->dy, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 298 | es->geometry.width, es->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 302 | move_grab_button(struct wl_pointer_grab *grab, |
Kristian Høgsberg | ed92f79 | 2012-03-30 11:31:25 -0400 | [diff] [blame] | 303 | uint32_t time, uint32_t button, int32_t state) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 304 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 305 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 306 | grab); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 307 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 308 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 309 | if (device->button_count == 0 && state == 0) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 310 | shell_grab_finish(shell_grab); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 311 | wl_input_device_end_pointer_grab(device); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 312 | free(grab); |
| 313 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 316 | static const struct wl_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 317 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 318 | move_grab_motion, |
| 319 | move_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 320 | }; |
| 321 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 322 | static void |
| 323 | unresponsive_surface_fade(struct shell_surface *shsurf, bool reverse) |
| 324 | { |
| 325 | shsurf->unresponsive_animation.fading_in = reverse ? 0 : 1; |
| 326 | |
| 327 | if(!shsurf->unresponsive_animation.exists) { |
| 328 | wl_list_insert(&shsurf->surface->compositor->animation_list, |
| 329 | &shsurf->unresponsive_animation.current.link); |
| 330 | shsurf->unresponsive_animation.exists = 1; |
| 331 | shsurf->unresponsive_animation.timestamp = weston_compositor_get_time(); |
| 332 | weston_surface_damage(shsurf->surface); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | static void |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 337 | unresponsive_fade_frame(struct weston_animation *animation, |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 338 | struct weston_output *output, uint32_t msecs) |
| 339 | { |
| 340 | struct shell_surface *shsurf = |
| 341 | container_of(animation, struct shell_surface, unresponsive_animation.current); |
| 342 | struct weston_surface *surface = shsurf->surface; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 343 | unsigned int step = 8; |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 344 | |
| 345 | if (!surface || !shsurf) |
| 346 | return; |
| 347 | |
| 348 | if (shsurf->unresponsive_animation.fading_in) { |
| 349 | while (step < msecs - shsurf->unresponsive_animation.timestamp) { |
| 350 | if (surface->saturation > 1) |
| 351 | surface->saturation -= 5; |
| 352 | if (surface->brightness > 200) |
| 353 | surface->brightness--; |
| 354 | |
| 355 | shsurf->unresponsive_animation.timestamp += step; |
| 356 | } |
| 357 | |
| 358 | if (surface->saturation <= 1 && surface->brightness <= 200) { |
| 359 | wl_list_remove(&shsurf->unresponsive_animation.current.link); |
| 360 | shsurf->unresponsive_animation.exists = 0; |
| 361 | } |
| 362 | } |
| 363 | else { |
| 364 | while (step < msecs - shsurf->unresponsive_animation.timestamp) { |
| 365 | if (surface->saturation < 255) |
| 366 | surface->saturation += 5; |
| 367 | if (surface->brightness < 255) |
| 368 | surface->brightness++; |
| 369 | |
| 370 | shsurf->unresponsive_animation.timestamp += step; |
| 371 | } |
| 372 | |
| 373 | if (surface->saturation >= 255 && surface->brightness >= 255) { |
| 374 | surface->saturation = surface->brightness = 255; |
| 375 | wl_list_remove(&shsurf->unresponsive_animation.current.link); |
| 376 | shsurf->unresponsive_animation.exists = 0; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | surface->geometry.dirty = 1; |
| 381 | weston_surface_damage(surface); |
| 382 | } |
| 383 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 384 | static void |
| 385 | ping_timer_destroy(struct shell_surface *shsurf) |
| 386 | { |
| 387 | if (!shsurf || !shsurf->ping_timer) |
| 388 | return; |
| 389 | |
| 390 | if (shsurf->ping_timer->source) |
| 391 | wl_event_source_remove(shsurf->ping_timer->source); |
| 392 | |
| 393 | free(shsurf->ping_timer); |
| 394 | shsurf->ping_timer = NULL; |
| 395 | } |
| 396 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 397 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 398 | ping_timeout_handler(void *data) |
| 399 | { |
| 400 | struct shell_surface *shsurf = data; |
| 401 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 402 | /* Client is not responding */ |
| 403 | shsurf->unresponsive = 1; |
| 404 | unresponsive_surface_fade(shsurf, false); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 405 | |
| 406 | return 1; |
| 407 | } |
| 408 | |
| 409 | static void |
| 410 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 411 | { |
| 412 | struct shell_surface *shsurf; |
| 413 | shsurf = get_shell_surface(surface); |
| 414 | struct wl_event_loop *loop; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 415 | int ping_timeout = 2500; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 416 | |
| 417 | if (!shsurf) |
| 418 | return; |
| 419 | |
| 420 | if (!shsurf->ping_timer) { |
| 421 | shsurf->ping_timer = malloc(sizeof shsurf->ping_timer); |
| 422 | if (!shsurf->ping_timer) |
| 423 | return; |
| 424 | |
| 425 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 426 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 427 | shsurf->ping_timer->source = |
| 428 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 429 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 430 | |
| 431 | wl_shell_surface_send_ping(&shsurf->resource, serial); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | static void |
| 436 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 437 | uint32_t serial) |
| 438 | { |
| 439 | struct shell_surface *shsurf = resource->data; |
| 440 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 441 | if (shsurf->ping_timer->serial == serial) { |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 442 | if (shsurf->unresponsive) { |
| 443 | /* Received pong from previously unresponsive client */ |
| 444 | unresponsive_surface_fade(shsurf, true); |
| 445 | } |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 446 | shsurf->unresponsive = 0; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 447 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | |
| 451 | static int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 452 | weston_surface_move(struct weston_surface *es, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 453 | struct weston_input_device *wd) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 454 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 455 | struct weston_move_grab *move; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 456 | struct shell_surface *shsurf = get_shell_surface(es); |
| 457 | |
| 458 | if (!shsurf) |
| 459 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 460 | |
| 461 | move = malloc(sizeof *move); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 462 | if (!move) |
| 463 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 464 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 465 | shell_grab_init(&move->base, &move_grab_interface, shsurf); |
| 466 | |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 467 | move->dx = es->geometry.x - wd->input_device.grab_x; |
| 468 | move->dy = es->geometry.y - wd->input_device.grab_y; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 469 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 470 | wl_input_device_start_pointer_grab(&wd->input_device, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 471 | &move->base.grab); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 472 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 473 | wl_input_device_set_pointer_focus(&wd->input_device, NULL, 0, 0); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 479 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 480 | struct wl_resource *input_resource, uint32_t serial) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 481 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 482 | struct weston_input_device *wd = input_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 483 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 484 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 485 | if (wd->input_device.button_count == 0 || |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 486 | wd->input_device.grab_serial != serial || |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 487 | wd->input_device.pointer_focus != &shsurf->surface->surface) |
| 488 | return; |
| 489 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 490 | if (weston_surface_move(shsurf->surface, wd) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 491 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 492 | } |
| 493 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 494 | struct weston_resize_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 495 | struct shell_grab base; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 496 | uint32_t edges; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 497 | int32_t width, height; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 498 | }; |
| 499 | |
| 500 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 501 | resize_grab_motion(struct wl_pointer_grab *grab, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 502 | uint32_t time, int32_t x, int32_t y) |
| 503 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 504 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 505 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 506 | int32_t width, height; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 507 | int32_t from_x, from_y; |
| 508 | int32_t to_x, to_y; |
| 509 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 510 | if (!resize->base.shsurf) |
| 511 | return; |
| 512 | |
| 513 | weston_surface_from_global(resize->base.shsurf->surface, |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 514 | device->grab_x, device->grab_y, |
| 515 | &from_x, &from_y); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 516 | weston_surface_from_global(resize->base.shsurf->surface, |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 517 | device->x, device->y, &to_x, &to_y); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 518 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 519 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 520 | width = resize->width + from_x - to_x; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 521 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 522 | width = resize->width + to_x - from_x; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 523 | } else { |
| 524 | width = resize->width; |
| 525 | } |
| 526 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 527 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 528 | height = resize->height + from_y - to_y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 529 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 530 | height = resize->height + to_y - from_y; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 531 | } else { |
| 532 | height = resize->height; |
| 533 | } |
| 534 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 535 | wl_shell_surface_send_configure(&resize->base.shsurf->resource, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 536 | resize->edges, width, height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 540 | resize_grab_button(struct wl_pointer_grab *grab, |
Kristian Høgsberg | ed92f79 | 2012-03-30 11:31:25 -0400 | [diff] [blame] | 541 | uint32_t time, uint32_t button, int32_t state) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 542 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 543 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 544 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 545 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 546 | if (device->button_count == 0 && state == 0) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 547 | shell_grab_finish(&resize->base); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 548 | wl_input_device_end_pointer_grab(device); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 549 | free(grab); |
| 550 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 551 | } |
| 552 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 553 | static const struct wl_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 554 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 555 | resize_grab_motion, |
| 556 | resize_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 557 | }; |
| 558 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 559 | static int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 560 | weston_surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 561 | struct weston_input_device *wd, uint32_t edges) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 562 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 563 | struct weston_resize_grab *resize; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 564 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 565 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 566 | return 0; |
Kristian Høgsberg | 0ce2457 | 2011-01-28 15:18:33 -0500 | [diff] [blame] | 567 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 568 | if (edges == 0 || edges > 15 || |
| 569 | (edges & 3) == 3 || (edges & 12) == 12) |
| 570 | return 0; |
| 571 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 572 | resize = malloc(sizeof *resize); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 573 | if (!resize) |
| 574 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 575 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 576 | shell_grab_init(&resize->base, &resize_grab_interface, shsurf); |
| 577 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 578 | resize->edges = edges; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 579 | resize->width = shsurf->surface->geometry.width; |
| 580 | resize->height = shsurf->surface->geometry.height; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 581 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 582 | wl_input_device_start_pointer_grab(&wd->input_device, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 583 | &resize->base.grab); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 584 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 585 | wl_input_device_set_pointer_focus(&wd->input_device, NULL, 0, 0); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 591 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 592 | struct wl_resource *input_resource, uint32_t serial, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 593 | uint32_t edges) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 594 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 595 | struct weston_input_device *wd = input_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 596 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 597 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 598 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 599 | return; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 600 | |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 601 | if (wd->input_device.button_count == 0 || |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 602 | wd->input_device.grab_serial != serial || |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 603 | wd->input_device.pointer_focus != &shsurf->surface->surface) |
| 604 | return; |
| 605 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 606 | if (weston_surface_resize(shsurf, wd, edges) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 607 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 608 | } |
| 609 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 610 | static struct weston_output * |
| 611 | get_default_output(struct weston_compositor *compositor) |
| 612 | { |
| 613 | return container_of(compositor->output_list.next, |
| 614 | struct weston_output, link); |
| 615 | } |
| 616 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 617 | static void |
| 618 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 619 | { |
| 620 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 621 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 622 | shell_surface_is_top_fullscreen(shsurf)) { |
| 623 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 624 | shsurf->fullscreen_output->origin); |
| 625 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 626 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 627 | shsurf->fullscreen.framerate = 0; |
| 628 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 629 | wl_list_init(&shsurf->fullscreen.transform.link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 630 | if (shsurf->fullscreen.black_surface) |
| 631 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 632 | shsurf->fullscreen.black_surface = NULL; |
| 633 | shsurf->fullscreen_output = NULL; |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 634 | shsurf->force_configure = 1; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 635 | weston_surface_set_position(shsurf->surface, |
| 636 | shsurf->saved_x, shsurf->saved_y); |
| 637 | } |
| 638 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 639 | static int |
| 640 | reset_shell_surface_type(struct shell_surface *surface) |
| 641 | { |
| 642 | switch (surface->type) { |
| 643 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 644 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 645 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 646 | case SHELL_SURFACE_MAXIMIZED: |
| 647 | surface->output = get_default_output(surface->surface->compositor); |
| 648 | weston_surface_set_position(surface->surface, |
| 649 | surface->saved_x, |
| 650 | surface->saved_y); |
| 651 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 652 | case SHELL_SURFACE_PANEL: |
| 653 | case SHELL_SURFACE_BACKGROUND: |
| 654 | wl_list_remove(&surface->link); |
| 655 | wl_list_init(&surface->link); |
| 656 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 657 | case SHELL_SURFACE_SCREENSAVER: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 658 | case SHELL_SURFACE_LOCK: |
| 659 | wl_resource_post_error(&surface->resource, |
| 660 | WL_DISPLAY_ERROR_INVALID_METHOD, |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 661 | "cannot reassign surface type"); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 662 | return -1; |
| 663 | case SHELL_SURFACE_NONE: |
| 664 | case SHELL_SURFACE_TOPLEVEL: |
| 665 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 666 | case SHELL_SURFACE_POPUP: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 667 | break; |
| 668 | } |
| 669 | |
| 670 | surface->type = SHELL_SURFACE_NONE; |
| 671 | return 0; |
| 672 | } |
| 673 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 674 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 675 | shell_surface_set_toplevel(struct wl_client *client, |
| 676 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 677 | |
| 678 | { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 679 | struct shell_surface *surface = resource->data; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 680 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 681 | if (reset_shell_surface_type(surface)) |
| 682 | return; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 683 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 684 | surface->type = SHELL_SURFACE_TOPLEVEL; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 688 | shell_surface_set_transient(struct wl_client *client, |
| 689 | struct wl_resource *resource, |
| 690 | struct wl_resource *parent_resource, |
| 691 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 692 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 693 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 694 | struct weston_surface *es = shsurf->surface; |
Pekka Paalanen | 01e7b00 | 2011-12-08 16:42:33 +0200 | [diff] [blame] | 695 | struct shell_surface *pshsurf = parent_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 696 | struct weston_surface *pes = pshsurf->surface; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 697 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 698 | if (reset_shell_surface_type(shsurf)) |
| 699 | return; |
| 700 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 701 | /* assign to parents output */ |
Alex Wu | 88277d1 | 2012-02-22 14:50:46 +0800 | [diff] [blame] | 702 | shsurf->output = pes->output; |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 703 | weston_surface_set_position(es, pes->geometry.x + x, |
| 704 | pes->geometry.y + y); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 705 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 706 | shsurf->type = SHELL_SURFACE_TRANSIENT; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 707 | } |
| 708 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 709 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 710 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 711 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 712 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 716 | get_output_panel_height(struct desktop_shell *shell, |
| 717 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 718 | { |
| 719 | struct shell_surface *priv; |
| 720 | int panel_height = 0; |
| 721 | |
| 722 | if (!output) |
| 723 | return 0; |
| 724 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 725 | wl_list_for_each(priv, &shell->panels, link) { |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 726 | if (priv->output == output) { |
| 727 | panel_height = priv->surface->geometry.height; |
| 728 | break; |
| 729 | } |
| 730 | } |
| 731 | return panel_height; |
| 732 | } |
| 733 | |
| 734 | static void |
| 735 | shell_surface_set_maximized(struct wl_client *client, |
| 736 | struct wl_resource *resource, |
| 737 | struct wl_resource *output_resource ) |
| 738 | { |
| 739 | struct shell_surface *shsurf = resource->data; |
| 740 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 741 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 742 | uint32_t edges = 0, panel_height = 0; |
| 743 | |
| 744 | /* get the default output, if the client set it as NULL |
| 745 | check whether the ouput is available */ |
| 746 | if (output_resource) |
| 747 | shsurf->output = output_resource->data; |
| 748 | else |
| 749 | shsurf->output = get_default_output(es->compositor); |
| 750 | |
| 751 | if (reset_shell_surface_type(shsurf)) |
| 752 | return; |
| 753 | |
| 754 | shsurf->saved_x = es->geometry.x; |
| 755 | shsurf->saved_y = es->geometry.y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 756 | shsurf->saved_position_valid = true; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 757 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 758 | shell = shell_surface_get_shell(shsurf); |
| 759 | panel_height = get_output_panel_height(shell, es->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 760 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 761 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 762 | wl_shell_surface_send_configure(&shsurf->resource, edges, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 763 | es->output->current->width, |
| 764 | es->output->current->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 765 | |
| 766 | shsurf->type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 767 | } |
| 768 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 769 | static void |
| 770 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy); |
| 771 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 772 | static struct weston_surface * |
| 773 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 774 | struct weston_surface *fs_surface, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 775 | GLfloat x, GLfloat y, int w, int h) |
| 776 | { |
| 777 | struct weston_surface *surface = NULL; |
| 778 | |
| 779 | surface = weston_surface_create(ec); |
| 780 | if (surface == NULL) { |
| 781 | fprintf(stderr, "no memory\n"); |
| 782 | return NULL; |
| 783 | } |
| 784 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 785 | surface->configure = black_surface_configure; |
| 786 | surface->private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 787 | weston_surface_configure(surface, x, y, w, h); |
| 788 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
| 789 | return surface; |
| 790 | } |
| 791 | |
| 792 | /* Create black surface and append it to the associated fullscreen surface. |
| 793 | * Handle size dismatch and positioning according to the method. */ |
| 794 | static void |
| 795 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 796 | { |
| 797 | struct weston_output *output = shsurf->fullscreen_output; |
| 798 | struct weston_surface *surface = shsurf->surface; |
| 799 | struct weston_matrix *matrix; |
| 800 | float scale; |
| 801 | |
| 802 | center_on_output(surface, output); |
| 803 | |
| 804 | if (!shsurf->fullscreen.black_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 805 | shsurf->fullscreen.black_surface = |
| 806 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 807 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 808 | output->x, output->y, |
| 809 | output->current->width, |
| 810 | output->current->height); |
| 811 | |
| 812 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
| 813 | wl_list_insert(&surface->layer_link, |
| 814 | &shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 815 | shsurf->fullscreen.black_surface->output = output; |
| 816 | |
| 817 | switch (shsurf->fullscreen.type) { |
| 818 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
| 819 | break; |
| 820 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
| 821 | matrix = &shsurf->fullscreen.transform.matrix; |
| 822 | weston_matrix_init(matrix); |
| 823 | scale = (float)output->current->width/(float)surface->geometry.width; |
| 824 | weston_matrix_scale(matrix, scale, scale, 1); |
| 825 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 826 | wl_list_insert(surface->geometry.transformation_list.prev, |
| 827 | &shsurf->fullscreen.transform.link); |
| 828 | weston_surface_set_position(surface, output->x, output->y); |
| 829 | break; |
| 830 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 831 | if (shell_surface_is_top_fullscreen(shsurf)) { |
| 832 | struct weston_mode mode = {0, |
| 833 | surface->geometry.width, |
| 834 | surface->geometry.height, |
| 835 | shsurf->fullscreen.framerate}; |
| 836 | |
| 837 | if (weston_output_switch_mode(output, &mode) == 0) { |
| 838 | weston_surface_configure(shsurf->fullscreen.black_surface, |
| 839 | output->x, output->y, |
| 840 | output->current->width, |
| 841 | output->current->height); |
| 842 | weston_surface_set_position(surface, output->x, output->y); |
| 843 | break; |
| 844 | } |
| 845 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 846 | break; |
| 847 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
| 848 | break; |
| 849 | default: |
| 850 | break; |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | /* make the fullscreen and black surface at the top */ |
| 855 | static void |
| 856 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 857 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 858 | struct weston_output *output = shsurf->fullscreen_output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 859 | struct weston_surface *surface = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 860 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 861 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 862 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 863 | wl_list_insert(&shell->fullscreen_layer.surface_list, |
| 864 | &surface->layer_link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 865 | weston_surface_damage(surface); |
| 866 | |
| 867 | if (!shsurf->fullscreen.black_surface) |
| 868 | shsurf->fullscreen.black_surface = |
| 869 | create_black_surface(surface->compositor, |
| 870 | surface, |
| 871 | output->x, output->y, |
| 872 | output->current->width, |
| 873 | output->current->height); |
| 874 | |
| 875 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 876 | wl_list_insert(&surface->layer_link, |
| 877 | &shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 878 | weston_surface_damage(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | static void |
| 882 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 883 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 884 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 885 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 886 | } |
| 887 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 888 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 889 | shell_surface_set_fullscreen(struct wl_client *client, |
Kristian Høgsberg | f856fd2 | 2012-02-16 15:58:14 -0500 | [diff] [blame] | 890 | struct wl_resource *resource, |
| 891 | uint32_t method, |
| 892 | uint32_t framerate, |
| 893 | struct wl_resource *output_resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 894 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 895 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 896 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 897 | |
| 898 | if (output_resource) |
| 899 | shsurf->output = output_resource->data; |
| 900 | else |
| 901 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 902 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 903 | if (reset_shell_surface_type(shsurf)) |
| 904 | return; |
| 905 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 906 | shsurf->fullscreen_output = shsurf->output; |
| 907 | shsurf->fullscreen.type = method; |
| 908 | shsurf->fullscreen.framerate = framerate; |
| 909 | shsurf->type = SHELL_SURFACE_FULLSCREEN; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 910 | |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 911 | shsurf->saved_x = es->geometry.x; |
| 912 | shsurf->saved_y = es->geometry.y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 913 | shsurf->saved_position_valid = true; |
| 914 | |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 915 | if (weston_surface_is_mapped(es)) |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 916 | shsurf->force_configure = 1; |
Kristian Høgsberg | d5ae9f4 | 2012-02-16 23:38:14 -0500 | [diff] [blame] | 917 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 918 | wl_shell_surface_send_configure(&shsurf->resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 919 | shsurf->output->current->width, |
| 920 | shsurf->output->current->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 921 | } |
| 922 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 923 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 924 | popup_grab_focus(struct wl_pointer_grab *grab, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 925 | struct wl_surface *surface, int32_t x, int32_t y) |
| 926 | { |
| 927 | struct wl_input_device *device = grab->input_device; |
| 928 | struct shell_surface *priv = |
| 929 | container_of(grab, struct shell_surface, popup.grab); |
| 930 | struct wl_client *client = priv->surface->surface.resource.client; |
| 931 | |
Pekka Paalanen | cb10843 | 2012-01-19 16:25:40 +0200 | [diff] [blame] | 932 | if (surface && surface->resource.client == client) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 933 | wl_input_device_set_pointer_focus(device, surface, x, y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 934 | grab->focus = surface; |
| 935 | } else { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 936 | wl_input_device_set_pointer_focus(device, NULL, 0, 0); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 937 | grab->focus = NULL; |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 942 | popup_grab_motion(struct wl_pointer_grab *grab, |
Pekka Paalanen | b29f412 | 2012-02-14 14:59:18 +0200 | [diff] [blame] | 943 | uint32_t time, int32_t sx, int32_t sy) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 944 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 945 | struct wl_resource *resource; |
| 946 | |
| 947 | resource = grab->input_device->pointer_focus_resource; |
| 948 | if (resource) |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 949 | wl_input_device_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 953 | popup_grab_button(struct wl_pointer_grab *grab, |
Kristian Høgsberg | ed92f79 | 2012-03-30 11:31:25 -0400 | [diff] [blame] | 954 | uint32_t time, uint32_t button, int32_t state) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 955 | { |
| 956 | struct wl_resource *resource; |
| 957 | struct shell_surface *shsurf = |
| 958 | container_of(grab, struct shell_surface, popup.grab); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 959 | struct wl_display *display; |
| 960 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 961 | |
| 962 | resource = grab->input_device->pointer_focus_resource; |
| 963 | if (resource) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 964 | display = wl_client_get_display(resource->client); |
| 965 | serial = wl_display_get_serial(display); |
| 966 | wl_input_device_send_button(resource, serial, |
| 967 | time, button, state); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 968 | } else if (state == 0 && |
| 969 | (shsurf->popup.initial_up || |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 970 | time - shsurf->popup.device->grab_time > 500)) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 971 | wl_shell_surface_send_popup_done(&shsurf->resource); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 972 | wl_input_device_end_pointer_grab(grab->input_device); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 973 | shsurf->popup.grab.input_device = NULL; |
| 974 | } |
| 975 | |
| 976 | if (state == 0) |
| 977 | shsurf->popup.initial_up = 1; |
| 978 | } |
| 979 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 980 | static const struct wl_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 981 | popup_grab_focus, |
| 982 | popup_grab_motion, |
| 983 | popup_grab_button, |
| 984 | }; |
| 985 | |
| 986 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 987 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 988 | { |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 989 | struct wl_input_device *device = shsurf->popup.device; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 990 | struct weston_surface *es = shsurf->surface; |
| 991 | struct weston_surface *parent = shsurf->parent->surface; |
| 992 | |
| 993 | es->output = parent->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 994 | shsurf->popup.grab.interface = &popup_grab_interface; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 995 | |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 996 | weston_surface_update_transform(parent); |
| 997 | if (parent->transform.enabled) { |
| 998 | shsurf->popup.parent_transform.matrix = |
| 999 | parent->transform.matrix; |
| 1000 | } else { |
| 1001 | /* construct x, y translation matrix */ |
| 1002 | weston_matrix_init(&shsurf->popup.parent_transform.matrix); |
| 1003 | shsurf->popup.parent_transform.matrix.d[12] = |
| 1004 | parent->geometry.x; |
| 1005 | shsurf->popup.parent_transform.matrix.d[13] = |
| 1006 | parent->geometry.y; |
| 1007 | } |
| 1008 | wl_list_insert(es->geometry.transformation_list.prev, |
| 1009 | &shsurf->popup.parent_transform.link); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1010 | weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1011 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1012 | shsurf->popup.initial_up = 0; |
| 1013 | |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1014 | /* We don't require the grab to still be active, but if another |
| 1015 | * grab has started in the meantime, we end the popup now. */ |
| 1016 | if (device->grab_serial == shsurf->popup.serial) { |
| 1017 | wl_input_device_start_pointer_grab(device, |
| 1018 | &shsurf->popup.grab); |
| 1019 | } else { |
| 1020 | wl_shell_surface_send_popup_done(&shsurf->resource); |
| 1021 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | static void |
| 1025 | shell_surface_set_popup(struct wl_client *client, |
| 1026 | struct wl_resource *resource, |
| 1027 | struct wl_resource *input_device_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1028 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1029 | struct wl_resource *parent_resource, |
| 1030 | int32_t x, int32_t y, uint32_t flags) |
| 1031 | { |
| 1032 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1033 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1034 | shsurf->type = SHELL_SURFACE_POPUP; |
| 1035 | shsurf->parent = parent_resource->data; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1036 | shsurf->popup.device = input_device_resource->data; |
| 1037 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1038 | shsurf->popup.x = x; |
| 1039 | shsurf->popup.y = y; |
| 1040 | } |
| 1041 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1042 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1043 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1044 | shell_surface_move, |
| 1045 | shell_surface_resize, |
| 1046 | shell_surface_set_toplevel, |
| 1047 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1048 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1049 | shell_surface_set_popup, |
| 1050 | shell_surface_set_maximized |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1051 | }; |
| 1052 | |
| 1053 | static void |
| 1054 | destroy_shell_surface(struct wl_resource *resource) |
| 1055 | { |
| 1056 | struct shell_surface *shsurf = resource->data; |
| 1057 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1058 | if (shsurf->popup.grab.input_device) |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1059 | wl_input_device_end_pointer_grab(shsurf->popup.grab.input_device); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1060 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1061 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1062 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1063 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1064 | shsurf->fullscreen_output->origin); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1065 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1066 | |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 1067 | if (shsurf->fullscreen.black_surface) |
| 1068 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
| 1069 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1070 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 1071 | * we can always remove the listener. |
| 1072 | */ |
| 1073 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 1074 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1075 | ping_timer_destroy(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1076 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1077 | wl_list_remove(&shsurf->link); |
| 1078 | free(shsurf); |
| 1079 | } |
| 1080 | |
| 1081 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1082 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1083 | { |
| 1084 | struct shell_surface *shsurf = container_of(listener, |
| 1085 | struct shell_surface, |
| 1086 | surface_destroy_listener); |
| 1087 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1088 | wl_resource_destroy(&shsurf->resource); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1091 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1092 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1093 | { |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1094 | struct wl_listener *listener; |
| 1095 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1096 | listener = wl_signal_get(&surface->surface.resource.destroy_signal, |
| 1097 | shell_handle_surface_destroy); |
| 1098 | if (listener) |
| 1099 | return container_of(listener, struct shell_surface, |
| 1100 | surface_destroy_listener); |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1101 | |
| 1102 | return NULL; |
| 1103 | } |
| 1104 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1105 | static void |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1106 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
| 1107 | |
| 1108 | static void |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 1109 | shell_get_shell_surface(struct wl_client *client, |
| 1110 | struct wl_resource *resource, |
| 1111 | uint32_t id, |
| 1112 | struct wl_resource *surface_resource) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1113 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1114 | struct weston_surface *surface = surface_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1115 | struct shell_surface *shsurf; |
| 1116 | |
Pekka Paalanen | f32f1fc | 2011-11-29 16:05:28 +0200 | [diff] [blame] | 1117 | if (get_shell_surface(surface)) { |
| 1118 | wl_resource_post_error(surface_resource, |
| 1119 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1120 | "desktop_shell::get_shell_surface already requested"); |
Pekka Paalanen | f32f1fc | 2011-11-29 16:05:28 +0200 | [diff] [blame] | 1121 | return; |
| 1122 | } |
| 1123 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1124 | if (surface->configure) { |
| 1125 | wl_resource_post_error(surface_resource, |
| 1126 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1127 | "surface->configure already set"); |
| 1128 | return; |
| 1129 | } |
| 1130 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1131 | shsurf = calloc(1, sizeof *shsurf); |
| 1132 | if (!shsurf) { |
| 1133 | wl_resource_post_no_memory(resource); |
| 1134 | return; |
| 1135 | } |
| 1136 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1137 | surface->configure = shell_surface_configure; |
| 1138 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1139 | shsurf->unresponsive = 0; |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 1140 | shsurf->unresponsive_animation.exists = 0; |
| 1141 | shsurf->unresponsive_animation.fading_in = 0; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1142 | shsurf->unresponsive_animation.current.frame = unresponsive_fade_frame; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1143 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1144 | shsurf->resource.destroy = destroy_shell_surface; |
| 1145 | shsurf->resource.object.id = id; |
| 1146 | shsurf->resource.object.interface = &wl_shell_surface_interface; |
| 1147 | shsurf->resource.object.implementation = |
| 1148 | (void (**)(void)) &shell_surface_implementation; |
| 1149 | shsurf->resource.data = shsurf; |
| 1150 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1151 | shsurf->shell = resource->data; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1152 | shsurf->saved_position_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1153 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1154 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 1155 | shsurf->fullscreen.framerate = 0; |
| 1156 | shsurf->fullscreen.black_surface = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1157 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1158 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 1159 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1160 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
| 1161 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 1162 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1163 | |
| 1164 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 1165 | wl_list_init(&shsurf->link); |
| 1166 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1167 | /* empty when not in use */ |
| 1168 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1169 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1170 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1171 | shsurf->type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1172 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1173 | wl_client_add_resource(client, &shsurf->resource); |
| 1174 | } |
| 1175 | |
| 1176 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 1177 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1178 | }; |
| 1179 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1180 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1181 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1182 | { |
| 1183 | proc->pid = 0; |
| 1184 | } |
| 1185 | |
| 1186 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1187 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1188 | { |
| 1189 | if (shell->screensaver.binding) |
| 1190 | return; |
| 1191 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1192 | if (!shell->screensaver.path) |
| 1193 | return; |
| 1194 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 1195 | if (shell->screensaver.process.pid != 0) { |
| 1196 | fprintf(stderr, "old screensaver still running\n"); |
| 1197 | return; |
| 1198 | } |
| 1199 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1200 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1201 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1202 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1203 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1207 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1208 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1209 | if (shell->screensaver.process.pid == 0) |
| 1210 | return; |
| 1211 | |
| 1212 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1216 | show_screensaver(struct desktop_shell *shell, struct shell_surface *surface) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1217 | { |
| 1218 | struct wl_list *list; |
| 1219 | |
| 1220 | if (shell->lock_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1221 | list = &shell->lock_surface->surface->layer_link; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1222 | else |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1223 | list = &shell->lock_layer.surface_list; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1224 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1225 | wl_list_remove(&surface->surface->layer_link); |
| 1226 | wl_list_insert(list, &surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1227 | surface->surface->output = surface->output; |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 1228 | weston_surface_damage(surface->surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1232 | hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1233 | { |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1234 | wl_list_remove(&surface->surface->layer_link); |
| 1235 | wl_list_init(&surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1236 | surface->surface->output = NULL; |
| 1237 | } |
| 1238 | |
| 1239 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1240 | desktop_shell_set_background(struct wl_client *client, |
| 1241 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1242 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1243 | struct wl_resource *surface_resource) |
| 1244 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1245 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1246 | struct shell_surface *shsurf = surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1247 | struct weston_surface *surface = shsurf->surface; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1248 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1249 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1250 | if (reset_shell_surface_type(shsurf)) |
| 1251 | return; |
| 1252 | |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 1253 | wl_list_for_each(priv, &shell->backgrounds, link) { |
| 1254 | if (priv->output == output_resource->data) { |
| 1255 | priv->surface->output = NULL; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1256 | wl_list_remove(&priv->surface->layer_link); |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 1257 | wl_list_remove(&priv->link); |
| 1258 | break; |
| 1259 | } |
| 1260 | } |
| 1261 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1262 | shsurf->type = SHELL_SURFACE_BACKGROUND; |
| 1263 | shsurf->output = output_resource->data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1264 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1265 | wl_list_insert(&shell->backgrounds, &shsurf->link); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1266 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1267 | weston_surface_set_position(surface, shsurf->output->x, |
| 1268 | shsurf->output->y); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1269 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1270 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1271 | surface_resource, |
| 1272 | shsurf->output->current->width, |
| 1273 | shsurf->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | static void |
| 1277 | desktop_shell_set_panel(struct wl_client *client, |
| 1278 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1279 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1280 | struct wl_resource *surface_resource) |
| 1281 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1282 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1283 | struct shell_surface *shsurf = surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1284 | struct weston_surface *surface = shsurf->surface; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1285 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1286 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1287 | if (reset_shell_surface_type(shsurf)) |
| 1288 | return; |
| 1289 | |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 1290 | wl_list_for_each(priv, &shell->panels, link) { |
| 1291 | if (priv->output == output_resource->data) { |
| 1292 | priv->surface->output = NULL; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1293 | wl_list_remove(&priv->surface->layer_link); |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 1294 | wl_list_remove(&priv->link); |
| 1295 | break; |
| 1296 | } |
| 1297 | } |
| 1298 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1299 | shsurf->type = SHELL_SURFACE_PANEL; |
| 1300 | shsurf->output = output_resource->data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1301 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1302 | wl_list_insert(&shell->panels, &shsurf->link); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1303 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1304 | weston_surface_set_position(surface, shsurf->output->x, |
| 1305 | shsurf->output->y); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1306 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1307 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1308 | surface_resource, |
| 1309 | shsurf->output->current->width, |
| 1310 | shsurf->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1311 | } |
| 1312 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1313 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1314 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1315 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1316 | struct desktop_shell *shell = |
| 1317 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1318 | |
| 1319 | fprintf(stderr, "lock surface gone\n"); |
| 1320 | shell->lock_surface = NULL; |
| 1321 | } |
| 1322 | |
| 1323 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1324 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 1325 | struct wl_resource *resource, |
| 1326 | struct wl_resource *surface_resource) |
| 1327 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1328 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1329 | struct shell_surface *surface = surface_resource->data; |
| 1330 | |
| 1331 | if (reset_shell_surface_type(surface)) |
| 1332 | return; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1333 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1334 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1335 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1336 | if (!shell->locked) |
| 1337 | return; |
| 1338 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1339 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1340 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1341 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
| 1342 | wl_signal_add(&surface_resource->destroy_signal, |
| 1343 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1344 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1345 | shell->lock_surface->type = SHELL_SURFACE_LOCK; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1349 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1350 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1351 | struct shell_surface *tmp; |
| 1352 | |
| 1353 | wl_list_for_each(tmp, &shell->screensaver.surfaces, link) |
| 1354 | hide_screensaver(shell, tmp); |
| 1355 | |
| 1356 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1357 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1358 | wl_list_remove(&shell->lock_layer.link); |
| 1359 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 1360 | &shell->fullscreen_layer.link); |
| 1361 | wl_list_insert(&shell->fullscreen_layer.link, |
| 1362 | &shell->panel_layer.link); |
| 1363 | wl_list_insert(&shell->panel_layer.link, &shell->toplevel_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1364 | |
| 1365 | shell->locked = false; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 1366 | shell->compositor->idle_time = shell->compositor->option_idle_time; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1367 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 1368 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | static void |
| 1372 | desktop_shell_unlock(struct wl_client *client, |
| 1373 | struct wl_resource *resource) |
| 1374 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1375 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1376 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1377 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1378 | |
| 1379 | if (shell->locked) |
| 1380 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1381 | } |
| 1382 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1383 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 1384 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1385 | desktop_shell_set_panel, |
| 1386 | desktop_shell_set_lock_surface, |
| 1387 | desktop_shell_unlock |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1388 | }; |
| 1389 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1390 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1391 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1392 | { |
| 1393 | struct shell_surface *shsurf; |
| 1394 | |
| 1395 | shsurf = get_shell_surface(surface); |
| 1396 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1397 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1398 | return shsurf->type; |
| 1399 | } |
| 1400 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1401 | static void |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1402 | move_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1403 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1404 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1405 | struct weston_surface *surface = |
| 1406 | (struct weston_surface *) device->pointer_focus; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 1407 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1408 | if (surface == NULL) |
| 1409 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1410 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1411 | switch (get_shell_surface_type(surface)) { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1412 | case SHELL_SURFACE_PANEL: |
| 1413 | case SHELL_SURFACE_BACKGROUND: |
| 1414 | case SHELL_SURFACE_FULLSCREEN: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1415 | case SHELL_SURFACE_SCREENSAVER: |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1416 | return; |
| 1417 | default: |
| 1418 | break; |
| 1419 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 1420 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1421 | weston_surface_move(surface, (struct weston_input_device *) device); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | static void |
| 1425 | resize_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1426 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1427 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1428 | struct weston_surface *surface = |
| 1429 | (struct weston_surface *) device->pointer_focus; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1430 | uint32_t edges = 0; |
| 1431 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1432 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 1433 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1434 | if (surface == NULL) |
| 1435 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1436 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1437 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1438 | if (!shsurf) |
| 1439 | return; |
| 1440 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1441 | switch (shsurf->type) { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1442 | case SHELL_SURFACE_PANEL: |
| 1443 | case SHELL_SURFACE_BACKGROUND: |
| 1444 | case SHELL_SURFACE_FULLSCREEN: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1445 | case SHELL_SURFACE_SCREENSAVER: |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1446 | return; |
| 1447 | default: |
| 1448 | break; |
| 1449 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 1450 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1451 | weston_surface_from_global(surface, |
| 1452 | device->grab_x, device->grab_y, &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1453 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1454 | if (x < surface->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1455 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1456 | else if (x < 2 * surface->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1457 | edges |= 0; |
| 1458 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1459 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1460 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1461 | if (y < surface->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1462 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1463 | else if (y < 2 * surface->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1464 | edges |= 0; |
| 1465 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1466 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1467 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1468 | weston_surface_resize(shsurf, (struct weston_input_device *) device, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1469 | edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | static void |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 1473 | surface_opacity_binding(struct wl_input_device *device, uint32_t time, |
| 1474 | uint32_t key, uint32_t button, uint32_t axis, int32_t value, void *data) |
| 1475 | { |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1476 | uint32_t step = 15; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 1477 | struct shell_surface *shsurf; |
| 1478 | struct weston_surface *surface = |
| 1479 | (struct weston_surface *) device->pointer_focus; |
| 1480 | |
| 1481 | if (surface == NULL) |
| 1482 | return; |
| 1483 | |
| 1484 | shsurf = get_shell_surface(surface); |
| 1485 | if (!shsurf) |
| 1486 | return; |
| 1487 | |
| 1488 | switch (shsurf->type) { |
| 1489 | case SHELL_SURFACE_BACKGROUND: |
| 1490 | case SHELL_SURFACE_SCREENSAVER: |
| 1491 | return; |
| 1492 | default: |
| 1493 | break; |
| 1494 | } |
| 1495 | |
| 1496 | surface->alpha += value * step; |
| 1497 | |
| 1498 | if (surface->alpha > 255) |
| 1499 | surface->alpha = 255; |
| 1500 | if (surface->alpha < step) |
| 1501 | surface->alpha = step; |
| 1502 | |
| 1503 | surface->geometry.dirty = 1; |
| 1504 | weston_surface_damage(surface); |
| 1505 | } |
| 1506 | |
| 1507 | static void |
Kristian Høgsberg | abcef3c | 2012-03-05 17:47:15 -0500 | [diff] [blame] | 1508 | zoom_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 1b45a79 | 2012-03-22 10:58:23 -0600 | [diff] [blame] | 1509 | uint32_t key, uint32_t button, uint32_t axis, int32_t value, void *data) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1510 | { |
| 1511 | struct weston_input_device *wd = (struct weston_input_device *) device; |
| 1512 | struct weston_compositor *compositor = wd->compositor; |
| 1513 | struct weston_output *output; |
| 1514 | |
| 1515 | wl_list_for_each(output, &compositor->output_list, link) { |
| 1516 | if (pixman_region32_contains_point(&output->region, |
| 1517 | device->x, device->y, NULL)) { |
Scott Moreau | 1b45a79 | 2012-03-22 10:58:23 -0600 | [diff] [blame] | 1518 | output->zoom.active = 1; |
| 1519 | output->zoom.level += output->zoom.increment * -value; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 1520 | |
| 1521 | if (output->zoom.level >= 1.0) { |
| 1522 | output->zoom.active = 0; |
| 1523 | output->zoom.level = 1.0; |
| 1524 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1525 | |
| 1526 | if (output->zoom.level < output->zoom.increment) |
| 1527 | output->zoom.level = output->zoom.increment; |
| 1528 | |
| 1529 | weston_output_update_zoom(output, device->x, device->y); |
| 1530 | } |
| 1531 | } |
| 1532 | } |
| 1533 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1534 | static void |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1535 | terminate_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1536 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1537 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1538 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1539 | |
| 1540 | if (state) |
| 1541 | wl_display_terminate(compositor->wl_display); |
| 1542 | } |
| 1543 | |
| 1544 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1545 | rotate_grab_motion(struct wl_pointer_grab *grab, |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1546 | uint32_t time, int32_t x, int32_t y) |
| 1547 | { |
| 1548 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1549 | container_of(grab, struct rotate_grab, base.grab); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1550 | struct wl_input_device *device = grab->input_device; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1551 | struct shell_surface *shsurf = rotate->base.shsurf; |
| 1552 | struct weston_surface *surface; |
| 1553 | GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
| 1554 | |
| 1555 | if (!shsurf) |
| 1556 | return; |
| 1557 | |
| 1558 | surface = shsurf->surface; |
| 1559 | |
| 1560 | cx = 0.5f * surface->geometry.width; |
| 1561 | cy = 0.5f * surface->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1562 | |
| 1563 | dx = device->x - rotate->center.x; |
| 1564 | dy = device->y - rotate->center.y; |
| 1565 | r = sqrtf(dx * dx + dy * dy); |
| 1566 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1567 | wl_list_remove(&shsurf->rotation.transform.link); |
| 1568 | shsurf->surface->geometry.dirty = 1; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1569 | |
| 1570 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1571 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1572 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1573 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1574 | weston_matrix_init(&rotate->rotation); |
| 1575 | rotate->rotation.d[0] = dx / r; |
| 1576 | rotate->rotation.d[4] = -dy / r; |
| 1577 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 1578 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1579 | |
| 1580 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 1581 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1582 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1583 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 1584 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1585 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 1586 | wl_list_insert( |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1587 | &shsurf->surface->geometry.transformation_list, |
| 1588 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1589 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1590 | wl_list_init(&shsurf->rotation.transform.link); |
| 1591 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1592 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1593 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 1594 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 1595 | /* We need to adjust the position of the surface |
| 1596 | * in case it was resized in a rotated state before */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1597 | cposx = surface->geometry.x + cx; |
| 1598 | cposy = surface->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 1599 | dposx = rotate->center.x - cposx; |
| 1600 | dposy = rotate->center.y - cposy; |
| 1601 | if (dposx != 0.0f || dposy != 0.0f) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1602 | weston_surface_set_position(surface, |
| 1603 | surface->geometry.x + dposx, |
| 1604 | surface->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 1605 | } |
| 1606 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 1607 | /* Repaint implies weston_surface_update_transform(), which |
| 1608 | * lazily applies the damage due to rotation update. |
| 1609 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1610 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1614 | rotate_grab_button(struct wl_pointer_grab *grab, |
Kristian Høgsberg | ed92f79 | 2012-03-30 11:31:25 -0400 | [diff] [blame] | 1615 | uint32_t time, uint32_t button, int32_t state) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1616 | { |
| 1617 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1618 | container_of(grab, struct rotate_grab, base.grab); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1619 | struct wl_input_device *device = grab->input_device; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1620 | struct shell_surface *shsurf = rotate->base.shsurf; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1621 | |
| 1622 | if (device->button_count == 0 && state == 0) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1623 | if (shsurf) |
| 1624 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 1625 | &rotate->rotation); |
| 1626 | shell_grab_finish(&rotate->base); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1627 | wl_input_device_end_pointer_grab(device); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1628 | free(rotate); |
| 1629 | } |
| 1630 | } |
| 1631 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1632 | static const struct wl_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1633 | noop_grab_focus, |
| 1634 | rotate_grab_motion, |
| 1635 | rotate_grab_button, |
| 1636 | }; |
| 1637 | |
| 1638 | static void |
| 1639 | rotate_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1640 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1641 | { |
| 1642 | struct weston_surface *base_surface = |
| 1643 | (struct weston_surface *) device->pointer_focus; |
| 1644 | struct shell_surface *surface; |
| 1645 | struct rotate_grab *rotate; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 1646 | GLfloat dx, dy; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1647 | GLfloat r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1648 | |
| 1649 | if (base_surface == NULL) |
| 1650 | return; |
| 1651 | |
| 1652 | surface = get_shell_surface(base_surface); |
| 1653 | if (!surface) |
| 1654 | return; |
| 1655 | |
| 1656 | switch (surface->type) { |
| 1657 | case SHELL_SURFACE_PANEL: |
| 1658 | case SHELL_SURFACE_BACKGROUND: |
| 1659 | case SHELL_SURFACE_FULLSCREEN: |
| 1660 | case SHELL_SURFACE_SCREENSAVER: |
| 1661 | return; |
| 1662 | default: |
| 1663 | break; |
| 1664 | } |
| 1665 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1666 | rotate = malloc(sizeof *rotate); |
| 1667 | if (!rotate) |
| 1668 | return; |
| 1669 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1670 | shell_grab_init(&rotate->base, &rotate_grab_interface, surface); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1671 | |
| 1672 | weston_surface_to_global(surface->surface, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1673 | surface->surface->geometry.width / 2, |
| 1674 | surface->surface->geometry.height / 2, |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1675 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1676 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1677 | wl_input_device_start_pointer_grab(device, &rotate->base.grab); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1678 | |
| 1679 | dx = device->x - rotate->center.x; |
| 1680 | dy = device->y - rotate->center.y; |
| 1681 | r = sqrtf(dx * dx + dy * dy); |
| 1682 | if (r > 20.0f) { |
| 1683 | struct weston_matrix inverse; |
| 1684 | |
| 1685 | weston_matrix_init(&inverse); |
| 1686 | inverse.d[0] = dx / r; |
| 1687 | inverse.d[4] = dy / r; |
| 1688 | inverse.d[1] = -inverse.d[4]; |
| 1689 | inverse.d[5] = inverse.d[0]; |
| 1690 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 1691 | |
| 1692 | weston_matrix_init(&rotate->rotation); |
| 1693 | rotate->rotation.d[0] = dx / r; |
| 1694 | rotate->rotation.d[4] = -dy / r; |
| 1695 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 1696 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1697 | } else { |
| 1698 | weston_matrix_init(&surface->rotation.rotation); |
| 1699 | weston_matrix_init(&rotate->rotation); |
| 1700 | } |
| 1701 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1702 | wl_input_device_set_pointer_focus(device, NULL, 0, 0); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1706 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1707 | struct weston_input_device *device) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1708 | { |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1709 | struct weston_surface *surf, *prev; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1710 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1711 | weston_surface_activate(es, device); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1712 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1713 | switch (get_shell_surface_type(es)) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1714 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1715 | case SHELL_SURFACE_PANEL: |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1716 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1717 | break; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1718 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1719 | case SHELL_SURFACE_SCREENSAVER: |
| 1720 | /* always below lock surface */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1721 | if (shell->lock_surface) |
| 1722 | weston_surface_restack(es, |
| 1723 | &shell->lock_surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1724 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1725 | case SHELL_SURFACE_FULLSCREEN: |
| 1726 | /* should on top of panels */ |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1727 | shell_stack_fullscreen(get_shell_surface(es)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1728 | shell_configure_fullscreen(get_shell_surface(es)); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1729 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1730 | default: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1731 | /* move the fullscreen surfaces down into the toplevel layer */ |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1732 | if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) { |
| 1733 | wl_list_for_each_reverse_safe(surf, |
| 1734 | prev, |
| 1735 | &shell->fullscreen_layer.surface_list, |
| 1736 | layer_link) |
| 1737 | weston_surface_restack(surf, |
| 1738 | &shell->toplevel_layer.surface_list); |
| 1739 | } |
| 1740 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1741 | weston_surface_restack(es, |
| 1742 | &shell->toplevel_layer.surface_list); |
| 1743 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1747 | /* no-op func for checking black surface */ |
| 1748 | static void |
| 1749 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 1750 | { |
| 1751 | } |
| 1752 | |
| 1753 | static bool |
| 1754 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 1755 | { |
| 1756 | if (es->configure == black_surface_configure) { |
| 1757 | if (fs_surface) |
| 1758 | *fs_surface = (struct weston_surface *)es->private; |
| 1759 | return true; |
| 1760 | } |
| 1761 | return false; |
| 1762 | } |
| 1763 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1764 | static void |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1765 | click_to_activate_binding(struct wl_input_device *device, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1766 | uint32_t time, uint32_t key, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 1767 | uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1768 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1769 | struct weston_input_device *wd = (struct weston_input_device *) device; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1770 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1771 | struct weston_surface *focus; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1772 | struct weston_surface *upper; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1773 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1774 | focus = (struct weston_surface *) device->pointer_focus; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 1775 | if (!focus) |
| 1776 | return; |
| 1777 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1778 | if (is_black_surface(focus, &upper)) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1779 | focus = upper; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1780 | |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 1781 | if (state && device->pointer_grab == &device->default_pointer_grab) |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1782 | activate(shell, focus, wd); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1786 | lock(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1787 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1788 | struct desktop_shell *shell = |
| 1789 | container_of(listener, struct desktop_shell, lock_listener); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1790 | struct weston_input_device *device; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1791 | struct shell_surface *shsurf; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1792 | struct weston_output *output; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1793 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1794 | if (shell->locked) { |
| 1795 | wl_list_for_each(output, &shell->compositor->output_list, link) |
| 1796 | /* TODO: find a way to jump to other DPMS levels */ |
| 1797 | if (output->set_dpms) |
| 1798 | output->set_dpms(output, WESTON_DPMS_STANDBY); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1799 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1800 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1801 | |
| 1802 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1803 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1804 | /* Hide all surfaces by removing the fullscreen, panel and |
| 1805 | * toplevel layers. This way nothing else can show or receive |
| 1806 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1807 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1808 | wl_list_remove(&shell->panel_layer.link); |
| 1809 | wl_list_remove(&shell->toplevel_layer.link); |
| 1810 | wl_list_remove(&shell->fullscreen_layer.link); |
| 1811 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 1812 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1813 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1814 | launch_screensaver(shell); |
| 1815 | |
| 1816 | wl_list_for_each(shsurf, &shell->screensaver.surfaces, link) |
| 1817 | show_screensaver(shell, shsurf); |
| 1818 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1819 | if (!wl_list_empty(&shell->screensaver.surfaces)) { |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 1820 | shell->compositor->idle_time = shell->screensaver.duration; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1821 | weston_compositor_wake(shell->compositor); |
| 1822 | shell->compositor->state = WESTON_COMPOSITOR_IDLE; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1823 | } |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 1824 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1825 | /* reset pointer foci */ |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 1826 | weston_compositor_schedule_repaint(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1827 | |
| 1828 | /* reset keyboard foci */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1829 | wl_list_for_each(device, &shell->compositor->input_device_list, link) { |
| 1830 | wl_input_device_set_keyboard_focus(&device->input_device, |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1831 | NULL); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | /* TODO: disable bindings that should not work while locked. */ |
| 1835 | |
| 1836 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1840 | unlock(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1841 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1842 | struct desktop_shell *shell = |
| 1843 | container_of(listener, struct desktop_shell, unlock_listener); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1844 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 1845 | if (!shell->locked || shell->lock_surface) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1846 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1847 | return; |
| 1848 | } |
| 1849 | |
| 1850 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 1851 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1852 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1853 | return; |
| 1854 | } |
| 1855 | |
| 1856 | if (shell->prepare_event_sent) |
| 1857 | return; |
| 1858 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1859 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1860 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1864 | center_on_output(struct weston_surface *surface, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1865 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1866 | struct weston_mode *mode = output->current; |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1867 | GLfloat x = (mode->width - surface->geometry.width) / 2; |
| 1868 | GLfloat y = (mode->height - surface->geometry.height) / 2; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1869 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1870 | weston_surface_set_position(surface, output->x + x, output->y + y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1874 | map(struct desktop_shell *shell, struct weston_surface *surface, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 1875 | 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] | 1876 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1877 | struct weston_compositor *compositor = shell->compositor; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1878 | struct shell_surface *shsurf; |
| 1879 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 1880 | struct weston_surface *parent; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1881 | int panel_height = 0; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1882 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1883 | shsurf = get_shell_surface(surface); |
| 1884 | if (shsurf) |
| 1885 | surface_type = shsurf->type; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1886 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1887 | surface->geometry.width = width; |
| 1888 | surface->geometry.height = height; |
| 1889 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1890 | |
| 1891 | /* initial positioning, see also configure() */ |
| 1892 | switch (surface_type) { |
| 1893 | case SHELL_SURFACE_TOPLEVEL: |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1894 | weston_surface_set_position(surface, 10 + random() % 400, |
| 1895 | 10 + random() % 400); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1896 | break; |
| 1897 | case SHELL_SURFACE_SCREENSAVER: |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 1898 | center_on_output(surface, shsurf->fullscreen_output); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1899 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1900 | case SHELL_SURFACE_FULLSCREEN: |
| 1901 | shell_map_fullscreen(shsurf); |
| 1902 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1903 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1904 | /* use surface configure to set the geometry */ |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1905 | panel_height = get_output_panel_height(shell,surface->output); |
| 1906 | weston_surface_set_position(surface, surface->output->x, |
| 1907 | surface->output->y + panel_height); |
| 1908 | break; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1909 | case SHELL_SURFACE_LOCK: |
| 1910 | center_on_output(surface, get_default_output(compositor)); |
| 1911 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 1912 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1913 | shell_map_popup(shsurf); |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 1914 | case SHELL_SURFACE_NONE: |
| 1915 | weston_surface_set_position(surface, |
| 1916 | surface->geometry.x + sx, |
| 1917 | surface->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 1918 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1919 | default: |
| 1920 | ; |
| 1921 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1922 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1923 | /* surface stacking order, see also activate() */ |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1924 | switch (surface_type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1925 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1926 | /* background always visible, at the bottom */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1927 | wl_list_insert(&shell->background_layer.surface_list, |
| 1928 | &surface->layer_link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1929 | break; |
| 1930 | case SHELL_SURFACE_PANEL: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1931 | /* panel always on top, hidden while locked */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1932 | wl_list_insert(&shell->panel_layer.surface_list, |
| 1933 | &surface->layer_link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1934 | break; |
| 1935 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1936 | /* lock surface always visible, on top */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1937 | wl_list_insert(&shell->lock_layer.surface_list, |
| 1938 | &surface->layer_link); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1939 | weston_compositor_wake(compositor); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1940 | break; |
| 1941 | case SHELL_SURFACE_SCREENSAVER: |
| 1942 | /* If locked, show it. */ |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 1943 | if (shell->locked) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1944 | show_screensaver(shell, shsurf); |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 1945 | compositor->idle_time = shell->screensaver.duration; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1946 | weston_compositor_wake(compositor); |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 1947 | if (!shell->lock_surface) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1948 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 1949 | } |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1950 | break; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 1951 | case SHELL_SURFACE_POPUP: |
| 1952 | case SHELL_SURFACE_TRANSIENT: |
| 1953 | parent = shsurf->parent->surface; |
| 1954 | wl_list_insert(parent->layer_link.prev, &surface->layer_link); |
| 1955 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1956 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 1957 | case SHELL_SURFACE_NONE: |
| 1958 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1959 | default: |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1960 | wl_list_insert(&shell->toplevel_layer.surface_list, |
| 1961 | &surface->layer_link); |
| 1962 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1963 | } |
| 1964 | |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 1965 | if (surface_type != SHELL_SURFACE_NONE) { |
| 1966 | weston_surface_assign_output(surface); |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 1967 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 1968 | surface->output = shsurf->output; |
| 1969 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 1970 | |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 1971 | switch (surface_type) { |
| 1972 | case SHELL_SURFACE_TOPLEVEL: |
| 1973 | case SHELL_SURFACE_TRANSIENT: |
| 1974 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1975 | case SHELL_SURFACE_MAXIMIZED: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 1976 | if (!shell->locked) |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1977 | activate(shell, surface, |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1978 | (struct weston_input_device *) |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1979 | compositor->input_device); |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 1980 | break; |
| 1981 | default: |
| 1982 | break; |
| 1983 | } |
| 1984 | |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 1985 | if (surface_type == SHELL_SURFACE_TOPLEVEL) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1986 | weston_zoom_run(surface, 0.8, 1.0, NULL, NULL); |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1987 | } |
| 1988 | |
| 1989 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1990 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1991 | GLfloat x, GLfloat y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1992 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1993 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 1994 | struct shell_surface *shsurf; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1995 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1996 | shsurf = get_shell_surface(surface); |
| 1997 | if (shsurf) |
| 1998 | surface_type = shsurf->type; |
| 1999 | |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2000 | surface->geometry.x = x; |
| 2001 | surface->geometry.y = y; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2002 | surface->geometry.width = width; |
| 2003 | surface->geometry.height = height; |
| 2004 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2005 | |
| 2006 | switch (surface_type) { |
| 2007 | case SHELL_SURFACE_SCREENSAVER: |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 2008 | center_on_output(surface, shsurf->fullscreen_output); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2009 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2010 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2011 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2012 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2013 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2014 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2015 | /* setting x, y and using configure to change that geometry */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2016 | surface->geometry.x = surface->output->x; |
| 2017 | surface->geometry.y = surface->output->y + |
| 2018 | get_output_panel_height(shell,surface->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2019 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2020 | case SHELL_SURFACE_TOPLEVEL: |
| 2021 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2022 | default: |
| 2023 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2024 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2025 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2026 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2027 | if (surface->output) { |
Pekka Paalanen | f07cb5d | 2012-02-10 13:34:36 +0200 | [diff] [blame] | 2028 | weston_surface_assign_output(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2029 | |
| 2030 | if (surface_type == SHELL_SURFACE_SCREENSAVER) |
| 2031 | surface->output = shsurf->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2032 | else if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 2033 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2034 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2035 | } |
| 2036 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2037 | static void |
| 2038 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2039 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 2040 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2041 | struct desktop_shell *shell = shsurf->shell; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2042 | |
| 2043 | if (!weston_surface_is_mapped(es)) { |
| 2044 | map(shell, es, es->buffer->width, es->buffer->height, sx, sy); |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 2045 | } else if (shsurf->force_configure || sx != 0 || sy != 0 || |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2046 | es->geometry.width != es->buffer->width || |
| 2047 | es->geometry.height != es->buffer->height) { |
| 2048 | GLfloat from_x, from_y; |
| 2049 | GLfloat to_x, to_y; |
| 2050 | |
| 2051 | weston_surface_to_global_float(es, 0, 0, &from_x, &from_y); |
| 2052 | weston_surface_to_global_float(es, sx, sy, &to_x, &to_y); |
| 2053 | configure(shell, es, |
| 2054 | es->geometry.x + to_x - from_x, |
| 2055 | es->geometry.y + to_y - from_y, |
| 2056 | es->buffer->width, es->buffer->height); |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 2057 | shsurf->force_configure = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2061 | static int launch_desktop_shell_process(struct desktop_shell *shell); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2062 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2063 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2064 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2065 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2066 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2067 | struct desktop_shell *shell = |
| 2068 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2069 | |
| 2070 | shell->child.process.pid = 0; |
| 2071 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2072 | |
| 2073 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 2074 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 2075 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2076 | shell->child.deathstamp = time; |
| 2077 | shell->child.deathcount = 0; |
| 2078 | } |
| 2079 | |
| 2080 | shell->child.deathcount++; |
| 2081 | if (shell->child.deathcount > 5) { |
| 2082 | fprintf(stderr, "weston-desktop-shell died, giving up.\n"); |
| 2083 | return; |
| 2084 | } |
| 2085 | |
| 2086 | fprintf(stderr, "weston-desktop-shell died, respawning...\n"); |
| 2087 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2091 | launch_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2092 | { |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 2093 | const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2094 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2095 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 2096 | &shell->child.process, |
| 2097 | shell_exe, |
| 2098 | desktop_shell_sigchld); |
| 2099 | |
| 2100 | if (!shell->child.client) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2101 | return -1; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2106 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 2107 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2108 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2109 | |
| 2110 | wl_client_add_object(client, &wl_shell_interface, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2111 | &shell_implementation, id, shell); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2112 | } |
| 2113 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2114 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2115 | unbind_desktop_shell(struct wl_resource *resource) |
| 2116 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2117 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2118 | |
| 2119 | if (shell->locked) |
| 2120 | resume_desktop(shell); |
| 2121 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2122 | shell->child.desktop_shell = NULL; |
| 2123 | shell->prepare_event_sent = false; |
| 2124 | free(resource); |
| 2125 | } |
| 2126 | |
| 2127 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2128 | bind_desktop_shell(struct wl_client *client, |
| 2129 | void *data, uint32_t version, uint32_t id) |
| 2130 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2131 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2132 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2133 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2134 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 2135 | &desktop_shell_implementation, |
| 2136 | id, shell); |
| 2137 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2138 | if (client == shell->child.client) { |
| 2139 | resource->destroy = unbind_desktop_shell; |
| 2140 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2141 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2142 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2143 | |
| 2144 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2145 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2146 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2147 | } |
| 2148 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2149 | static void |
| 2150 | screensaver_set_surface(struct wl_client *client, |
| 2151 | struct wl_resource *resource, |
| 2152 | struct wl_resource *shell_surface_resource, |
| 2153 | struct wl_resource *output_resource) |
| 2154 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2155 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2156 | struct shell_surface *surface = shell_surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2157 | struct weston_output *output = output_resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2158 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2159 | if (reset_shell_surface_type(surface)) |
| 2160 | return; |
| 2161 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2162 | surface->type = SHELL_SURFACE_SCREENSAVER; |
| 2163 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 2164 | surface->fullscreen_output = output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2165 | surface->output = output; |
| 2166 | wl_list_insert(shell->screensaver.surfaces.prev, &surface->link); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | static const struct screensaver_interface screensaver_implementation = { |
| 2170 | screensaver_set_surface |
| 2171 | }; |
| 2172 | |
| 2173 | static void |
| 2174 | unbind_screensaver(struct wl_resource *resource) |
| 2175 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2176 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2177 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2178 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2179 | free(resource); |
| 2180 | } |
| 2181 | |
| 2182 | static void |
| 2183 | bind_screensaver(struct wl_client *client, |
| 2184 | void *data, uint32_t version, uint32_t id) |
| 2185 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2186 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2187 | struct wl_resource *resource; |
| 2188 | |
| 2189 | resource = wl_client_add_object(client, &screensaver_interface, |
| 2190 | &screensaver_implementation, |
| 2191 | id, shell); |
| 2192 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2193 | if (shell->screensaver.binding == NULL) { |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2194 | resource->destroy = unbind_screensaver; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2195 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2196 | return; |
| 2197 | } |
| 2198 | |
| 2199 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2200 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2201 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2202 | } |
| 2203 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2204 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2205 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2206 | struct weston_surface *current; |
| 2207 | struct wl_listener listener; |
| 2208 | struct wl_keyboard_grab grab; |
| 2209 | }; |
| 2210 | |
| 2211 | static void |
| 2212 | switcher_next(struct switcher *switcher) |
| 2213 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2214 | struct weston_compositor *compositor = switcher->shell->compositor; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2215 | struct weston_surface *surface; |
| 2216 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 2217 | struct shell_surface *shsurf; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2218 | |
| 2219 | wl_list_for_each(surface, &compositor->surface_list, link) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2220 | switch (get_shell_surface_type(surface)) { |
| 2221 | case SHELL_SURFACE_TOPLEVEL: |
| 2222 | case SHELL_SURFACE_FULLSCREEN: |
| 2223 | case SHELL_SURFACE_MAXIMIZED: |
| 2224 | if (first == NULL) |
| 2225 | first = surface; |
| 2226 | if (prev == switcher->current) |
| 2227 | next = surface; |
| 2228 | prev = surface; |
| 2229 | surface->alpha = 64; |
Kristian Høgsberg | cacb7cd | 2012-02-28 09:20:21 -0500 | [diff] [blame] | 2230 | surface->geometry.dirty = 1; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2231 | weston_surface_damage(surface); |
| 2232 | break; |
| 2233 | default: |
| 2234 | break; |
| 2235 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 2236 | |
| 2237 | if (is_black_surface(surface, NULL)) { |
| 2238 | surface->alpha = 64; |
| 2239 | surface->geometry.dirty = 1; |
| 2240 | weston_surface_damage(surface); |
| 2241 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | if (next == NULL) |
| 2245 | next = first; |
| 2246 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 2247 | if (next == NULL) |
| 2248 | return; |
| 2249 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2250 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2251 | wl_signal_add(&next->surface.resource.destroy_signal, |
| 2252 | &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2253 | |
| 2254 | switcher->current = next; |
| 2255 | next->alpha = 255; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 2256 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 2257 | shsurf = get_shell_surface(switcher->current); |
| 2258 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
| 2259 | shsurf->fullscreen.black_surface->alpha = 255; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2263 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2264 | { |
| 2265 | struct switcher *switcher = |
| 2266 | container_of(listener, struct switcher, listener); |
| 2267 | |
| 2268 | switcher_next(switcher); |
| 2269 | } |
| 2270 | |
| 2271 | static void |
| 2272 | switcher_destroy(struct switcher *switcher, uint32_t time) |
| 2273 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2274 | struct weston_compositor *compositor = switcher->shell->compositor; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2275 | struct weston_surface *surface; |
| 2276 | struct weston_input_device *device = |
| 2277 | (struct weston_input_device *) switcher->grab.input_device; |
| 2278 | |
| 2279 | wl_list_for_each(surface, &compositor->surface_list, link) { |
| 2280 | surface->alpha = 255; |
| 2281 | weston_surface_damage(surface); |
| 2282 | } |
| 2283 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 2284 | if (switcher->current) |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2285 | activate(switcher->shell, switcher->current, device); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2286 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2287 | wl_input_device_end_keyboard_grab(&device->input_device); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2288 | free(switcher); |
| 2289 | } |
| 2290 | |
| 2291 | static void |
| 2292 | switcher_key(struct wl_keyboard_grab *grab, |
| 2293 | uint32_t time, uint32_t key, int32_t state) |
| 2294 | { |
| 2295 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
| 2296 | struct weston_input_device *device = |
| 2297 | (struct weston_input_device *) grab->input_device; |
| 2298 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame^] | 2299 | if ((device->modifier_state & switcher->shell->binding_modifier) == 0) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2300 | switcher_destroy(switcher, time); |
| 2301 | } else if (key == KEY_TAB && state) { |
| 2302 | switcher_next(switcher); |
| 2303 | } |
| 2304 | }; |
| 2305 | |
| 2306 | static const struct wl_keyboard_grab_interface switcher_grab = { |
| 2307 | switcher_key |
| 2308 | }; |
| 2309 | |
| 2310 | static void |
| 2311 | switcher_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2312 | uint32_t key, uint32_t button, uint32_t axis, |
| 2313 | int32_t state, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2314 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2315 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2316 | struct switcher *switcher; |
| 2317 | |
| 2318 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2319 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2320 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2321 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2322 | wl_list_init(&switcher->listener.link); |
| 2323 | |
| 2324 | switcher->grab.interface = &switcher_grab; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2325 | wl_input_device_start_keyboard_grab(device, &switcher->grab); |
| 2326 | wl_input_device_set_keyboard_focus(device, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2327 | switcher_next(switcher); |
| 2328 | } |
| 2329 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 2330 | static void |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2331 | backlight_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2332 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2333 | { |
| 2334 | struct weston_compositor *compositor = data; |
| 2335 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 2336 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2337 | |
| 2338 | /* TODO: we're limiting to simple use cases, where we assume just |
| 2339 | * control on the primary display. We'd have to extend later if we |
| 2340 | * ever get support for setting backlights on random desktop LCD |
| 2341 | * panels though */ |
| 2342 | output = get_default_output(compositor); |
| 2343 | if (!output) |
| 2344 | return; |
| 2345 | |
| 2346 | if (!output->set_backlight) |
| 2347 | return; |
| 2348 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 2349 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 2350 | backlight_new = output->backlight_current - 25; |
| 2351 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 2352 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2353 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 2354 | if (backlight_new < 5) |
| 2355 | backlight_new = 5; |
| 2356 | if (backlight_new > 255) |
| 2357 | backlight_new = 255; |
| 2358 | |
| 2359 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2360 | output->set_backlight(output, output->backlight_current); |
| 2361 | } |
| 2362 | |
| 2363 | static void |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 2364 | debug_repaint_binding(struct wl_input_device *device, uint32_t time, |
Scott Moreau | 6a3633d | 2012-03-20 08:47:59 -0600 | [diff] [blame] | 2365 | uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data) |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 2366 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2367 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2368 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 2369 | struct weston_surface *surface; |
| 2370 | |
| 2371 | if (shell->debug_repaint_surface) { |
| 2372 | weston_surface_destroy(shell->debug_repaint_surface); |
| 2373 | shell->debug_repaint_surface = NULL; |
| 2374 | } else { |
| 2375 | surface = weston_surface_create(compositor); |
| 2376 | weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2); |
| 2377 | weston_surface_configure(surface, 0, 0, 8192, 8192); |
| 2378 | wl_list_insert(&compositor->fade_layer.surface_list, |
| 2379 | &surface->layer_link); |
| 2380 | weston_surface_assign_output(surface); |
| 2381 | pixman_region32_init(&surface->input); |
| 2382 | |
| 2383 | /* Here's the dirty little trick that makes the |
| 2384 | * repaint debugging work: we force an |
| 2385 | * update_transform first to update dependent state |
| 2386 | * and clear the geometry.dirty bit. Then we clear |
| 2387 | * the surface damage so it only gets repainted |
| 2388 | * piecewise as we repaint other things. */ |
| 2389 | |
| 2390 | weston_surface_update_transform(surface); |
| 2391 | pixman_region32_fini(&surface->damage); |
| 2392 | pixman_region32_init(&surface->damage); |
| 2393 | shell->debug_repaint_surface = surface; |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2398 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 2399 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2400 | struct desktop_shell *shell = |
| 2401 | container_of(listener, struct desktop_shell, destroy_listener); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 2402 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 2403 | if (shell->child.client) |
| 2404 | wl_client_destroy(shell->child.client); |
| 2405 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 2406 | free(shell->screensaver.path); |
| 2407 | free(shell); |
| 2408 | } |
| 2409 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame^] | 2410 | static void |
| 2411 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 2412 | { |
| 2413 | uint32_t mod; |
| 2414 | |
| 2415 | /* fixed bindings */ |
| 2416 | weston_compositor_add_binding(ec, KEY_BACKSPACE, 0, 0, |
| 2417 | MODIFIER_CTRL | MODIFIER_ALT, |
| 2418 | terminate_binding, ec); |
| 2419 | weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0, |
| 2420 | click_to_activate_binding, shell); |
| 2421 | weston_compositor_add_binding(ec, 0, 0, |
| 2422 | WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL, |
| 2423 | MODIFIER_SUPER | MODIFIER_ALT, |
| 2424 | surface_opacity_binding, NULL); |
| 2425 | weston_compositor_add_binding(ec, 0, 0, |
| 2426 | WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL, |
| 2427 | MODIFIER_SUPER, zoom_binding, NULL); |
| 2428 | |
| 2429 | /* configurable bindings */ |
| 2430 | mod = shell->binding_modifier; |
| 2431 | weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, mod, |
| 2432 | move_binding, shell); |
| 2433 | weston_compositor_add_binding(ec, 0, BTN_MIDDLE, 0, mod, |
| 2434 | resize_binding, shell); |
| 2435 | weston_compositor_add_binding(ec, 0, BTN_RIGHT, 0, mod, |
| 2436 | rotate_binding, NULL); |
| 2437 | weston_compositor_add_binding(ec, KEY_TAB, 0, 0, mod, |
| 2438 | switcher_binding, shell); |
| 2439 | weston_compositor_add_binding(ec, KEY_F9, 0, 0, mod, |
| 2440 | backlight_binding, ec); |
| 2441 | weston_compositor_add_binding(ec, KEY_BRIGHTNESSDOWN, 0, 0, 0, |
| 2442 | backlight_binding, ec); |
| 2443 | weston_compositor_add_binding(ec, KEY_F10, 0, 0, mod, |
| 2444 | backlight_binding, ec); |
| 2445 | weston_compositor_add_binding(ec, KEY_BRIGHTNESSUP, 0, 0, 0, |
| 2446 | backlight_binding, ec); |
| 2447 | weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, mod, |
| 2448 | debug_repaint_binding, shell); |
| 2449 | } |
| 2450 | |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 2451 | int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2452 | shell_init(struct weston_compositor *ec); |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 2453 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2454 | WL_EXPORT int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2455 | shell_init(struct weston_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2456 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2457 | struct desktop_shell *shell; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2458 | |
| 2459 | shell = malloc(sizeof *shell); |
| 2460 | if (shell == NULL) |
| 2461 | return -1; |
| 2462 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 2463 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2464 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2465 | |
| 2466 | shell->destroy_listener.notify = shell_destroy; |
| 2467 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
| 2468 | shell->lock_listener.notify = lock; |
| 2469 | wl_signal_add(&ec->lock_signal, &shell->lock_listener); |
| 2470 | shell->unlock_listener.notify = unlock; |
| 2471 | wl_signal_add(&ec->unlock_signal, &shell->unlock_listener); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 2472 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2473 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2474 | wl_list_init(&shell->backgrounds); |
| 2475 | wl_list_init(&shell->panels); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2476 | wl_list_init(&shell->screensaver.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2477 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2478 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 2479 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
| 2480 | weston_layer_init(&shell->toplevel_layer, &shell->panel_layer.link); |
| 2481 | weston_layer_init(&shell->background_layer, |
| 2482 | &shell->toplevel_layer.link); |
| 2483 | wl_list_init(&shell->lock_layer.surface_list); |
| 2484 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 2485 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 2486 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2487 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 2488 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2489 | return -1; |
| 2490 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2491 | if (wl_display_add_global(ec->wl_display, |
| 2492 | &desktop_shell_interface, |
| 2493 | shell, bind_desktop_shell) == NULL) |
| 2494 | return -1; |
| 2495 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2496 | if (wl_display_add_global(ec->wl_display, &screensaver_interface, |
| 2497 | shell, bind_screensaver) == NULL) |
| 2498 | return -1; |
| 2499 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 2500 | shell->child.deathstamp = weston_compositor_get_time(); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2501 | if (launch_desktop_shell_process(shell) != 0) |
| 2502 | return -1; |
| 2503 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame^] | 2504 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2505 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 2506 | return 0; |
| 2507 | } |