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