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