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