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