Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 3 | * Copyright © 2011 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 | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 30 | #include <sys/types.h> |
| 31 | #include <sys/socket.h> |
| 32 | #include <fcntl.h> |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 33 | #include <assert.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" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 38 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 39 | struct wl_shell { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 40 | struct wlsc_compositor *compositor; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 41 | struct wlsc_shell shell; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 42 | struct wlsc_surface *panel; |
| 43 | struct wl_listener panel_listener; |
| 44 | struct wlsc_surface *background; |
| 45 | struct wl_listener background_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 46 | |
| 47 | struct { |
| 48 | struct wlsc_process process; |
| 49 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 50 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 51 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 52 | |
| 53 | bool locked; |
| 54 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 55 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 56 | struct wlsc_surface *lock_surface; |
| 57 | struct wl_listener lock_surface_listener; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 58 | struct wl_list hidden_surface_list; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 59 | }; |
| 60 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 61 | enum shell_surface_type { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 62 | SHELL_SURFACE_NORMAL, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 63 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 64 | SHELL_SURFACE_PANEL, |
| 65 | SHELL_SURFACE_BACKGROUND, |
| 66 | SHELL_SURFACE_LOCK, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 67 | |
| 68 | SHELL_SURFACE_TOPLEVEL, |
| 69 | SHELL_SURFACE_TRANSIENT, |
| 70 | SHELL_SURFACE_FULLSCREEN |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 71 | }; |
| 72 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 73 | struct shell_surface { |
| 74 | struct wl_listener destroy_listener; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 75 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 76 | enum shell_surface_type type; |
| 77 | int32_t saved_x, saved_y; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 80 | struct wlsc_move_grab { |
| 81 | struct wl_grab grab; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 82 | struct wlsc_surface *surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 83 | int32_t dx, dy; |
| 84 | }; |
| 85 | |
| 86 | static void |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 87 | destroy_shell_surface(struct shell_surface *priv) |
| 88 | { |
| 89 | wl_list_remove(&priv->destroy_listener.link); |
| 90 | free(priv); |
| 91 | } |
| 92 | |
| 93 | static void |
| 94 | handle_shell_surface_destroy(struct wl_listener *listener, |
| 95 | struct wl_resource *resource, uint32_t time) |
| 96 | { |
| 97 | struct shell_surface *priv = |
| 98 | container_of(listener, struct shell_surface, destroy_listener); |
| 99 | destroy_shell_surface(priv); |
| 100 | } |
| 101 | |
| 102 | static struct shell_surface * |
| 103 | get_shell_surface(struct wlsc_surface *surface) |
| 104 | { |
| 105 | struct shell_surface *priv; |
| 106 | |
| 107 | if (surface->shell_priv) |
| 108 | return surface->shell_priv; |
| 109 | |
| 110 | priv = calloc(1, sizeof *priv); |
| 111 | if (!priv) |
| 112 | return NULL; |
| 113 | |
| 114 | priv->destroy_listener.func = handle_shell_surface_destroy; |
| 115 | wl_list_insert(surface->surface.resource.destroy_listener_list.prev, |
| 116 | &priv->destroy_listener.link); |
| 117 | |
| 118 | surface->shell_priv = priv; |
| 119 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 120 | priv->type = SHELL_SURFACE_NORMAL; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 121 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 122 | return priv; |
| 123 | } |
| 124 | |
| 125 | static void |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 126 | move_grab_motion(struct wl_grab *grab, |
| 127 | uint32_t time, int32_t x, int32_t y) |
| 128 | { |
| 129 | struct wlsc_move_grab *move = (struct wlsc_move_grab *) grab; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 130 | struct wlsc_surface *es = move->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 131 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 132 | wlsc_surface_configure(es, x + move->dx, y + move->dy, |
| 133 | es->width, es->height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void |
| 137 | move_grab_button(struct wl_grab *grab, |
| 138 | uint32_t time, int32_t button, int32_t state) |
| 139 | { |
| 140 | } |
| 141 | |
| 142 | static void |
| 143 | move_grab_end(struct wl_grab *grab, uint32_t time) |
| 144 | { |
| 145 | free(grab); |
| 146 | } |
| 147 | |
| 148 | static const struct wl_grab_interface move_grab_interface = { |
| 149 | move_grab_motion, |
| 150 | move_grab_button, |
| 151 | move_grab_end |
| 152 | }; |
| 153 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 154 | static int |
| 155 | wlsc_surface_move(struct wlsc_surface *es, |
| 156 | struct wlsc_input_device *wd, uint32_t time) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 157 | { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 158 | struct wlsc_move_grab *move; |
| 159 | |
| 160 | move = malloc(sizeof *move); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 161 | if (!move) |
| 162 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 163 | |
| 164 | move->grab.interface = &move_grab_interface; |
| 165 | move->dx = es->x - wd->input_device.grab_x; |
| 166 | move->dy = es->y - wd->input_device.grab_y; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 167 | move->surface = es; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 168 | |
| 169 | if (wl_input_device_update_grab(&wd->input_device, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 170 | &move->grab, &es->surface, time) < 0) |
| 171 | return 0; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 172 | |
| 173 | wlsc_input_device_set_pointer_image(wd, WLSC_POINTER_DRAGGING); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 174 | wl_input_device_set_pointer_focus(&wd->input_device, |
| 175 | NULL, time, 0, 0, 0, 0); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static void |
| 181 | shell_move(struct wl_client *client, struct wl_resource *resource, |
| 182 | struct wl_resource *surface_resource, |
| 183 | struct wl_resource *input_resource, uint32_t time) |
| 184 | { |
| 185 | struct wlsc_input_device *wd = input_resource->data; |
| 186 | struct wlsc_surface *es = surface_resource->data; |
| 187 | |
| 188 | if (wlsc_surface_move(es, wd, time) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 189 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | struct wlsc_resize_grab { |
| 193 | struct wl_grab grab; |
| 194 | uint32_t edges; |
| 195 | int32_t dx, dy, width, height; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 196 | struct wlsc_surface *surface; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 197 | struct wl_resource *resource; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | static void |
| 201 | resize_grab_motion(struct wl_grab *grab, |
| 202 | uint32_t time, int32_t x, int32_t y) |
| 203 | { |
| 204 | struct wlsc_resize_grab *resize = (struct wlsc_resize_grab *) grab; |
| 205 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 206 | struct wl_surface *surface = &resize->surface->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 207 | int32_t width, height; |
| 208 | |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 209 | if (resize->edges & WL_SHELL_RESIZE_LEFT) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 210 | width = device->grab_x - x + resize->width; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 211 | } else if (resize->edges & WL_SHELL_RESIZE_RIGHT) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 212 | width = x - device->grab_x + resize->width; |
| 213 | } else { |
| 214 | width = resize->width; |
| 215 | } |
| 216 | |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 217 | if (resize->edges & WL_SHELL_RESIZE_TOP) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 218 | height = device->grab_y - y + resize->height; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 219 | } else if (resize->edges & WL_SHELL_RESIZE_BOTTOM) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 220 | height = y - device->grab_y + resize->height; |
| 221 | } else { |
| 222 | height = resize->height; |
| 223 | } |
| 224 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 225 | wl_resource_post_event(resize->resource, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 226 | WL_SHELL_CONFIGURE, time, resize->edges, |
| 227 | surface, width, height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static void |
| 231 | resize_grab_button(struct wl_grab *grab, |
| 232 | uint32_t time, int32_t button, int32_t state) |
| 233 | { |
| 234 | } |
| 235 | |
| 236 | static void |
| 237 | resize_grab_end(struct wl_grab *grab, uint32_t time) |
| 238 | { |
| 239 | free(grab); |
| 240 | } |
| 241 | |
| 242 | static const struct wl_grab_interface resize_grab_interface = { |
| 243 | resize_grab_motion, |
| 244 | resize_grab_button, |
| 245 | resize_grab_end |
| 246 | }; |
| 247 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 248 | static int |
| 249 | wlsc_surface_resize(struct wlsc_surface *es, |
| 250 | struct wlsc_input_device *wd, |
| 251 | uint32_t time, uint32_t edges, |
| 252 | struct wl_resource *resource) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 253 | { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 254 | struct wlsc_resize_grab *resize; |
| 255 | enum wlsc_pointer_type pointer = WLSC_POINTER_LEFT_PTR; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 256 | |
Kristian Høgsberg | 0ce2457 | 2011-01-28 15:18:33 -0500 | [diff] [blame] | 257 | /* FIXME: Reject if fullscreen */ |
| 258 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 259 | resize = malloc(sizeof *resize); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 260 | if (!resize) |
| 261 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 262 | |
| 263 | resize->grab.interface = &resize_grab_interface; |
| 264 | resize->edges = edges; |
| 265 | resize->dx = es->x - wd->input_device.grab_x; |
| 266 | resize->dy = es->y - wd->input_device.grab_y; |
| 267 | resize->width = es->width; |
| 268 | resize->height = es->height; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 269 | resize->surface = es; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 270 | resize->resource = resource; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 271 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 272 | if (edges == 0 || edges > 15 || |
| 273 | (edges & 3) == 3 || (edges & 12) == 12) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 274 | return 0; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 275 | |
| 276 | switch (edges) { |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 277 | case WL_SHELL_RESIZE_TOP: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 278 | pointer = WLSC_POINTER_TOP; |
| 279 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 280 | case WL_SHELL_RESIZE_BOTTOM: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 281 | pointer = WLSC_POINTER_BOTTOM; |
| 282 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 283 | case WL_SHELL_RESIZE_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 284 | pointer = WLSC_POINTER_LEFT; |
| 285 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 286 | case WL_SHELL_RESIZE_TOP_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 287 | pointer = WLSC_POINTER_TOP_LEFT; |
| 288 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 289 | case WL_SHELL_RESIZE_BOTTOM_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 290 | pointer = WLSC_POINTER_BOTTOM_LEFT; |
| 291 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 292 | case WL_SHELL_RESIZE_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 293 | pointer = WLSC_POINTER_RIGHT; |
| 294 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 295 | case WL_SHELL_RESIZE_TOP_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 296 | pointer = WLSC_POINTER_TOP_RIGHT; |
| 297 | break; |
Kristian Høgsberg | 027931b | 2011-01-21 21:57:55 -0500 | [diff] [blame] | 298 | case WL_SHELL_RESIZE_BOTTOM_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 299 | pointer = WLSC_POINTER_BOTTOM_RIGHT; |
| 300 | break; |
| 301 | } |
| 302 | |
| 303 | if (wl_input_device_update_grab(&wd->input_device, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 304 | &resize->grab, &es->surface, time) < 0) |
| 305 | return 0; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 306 | |
| 307 | wlsc_input_device_set_pointer_image(wd, pointer); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 308 | wl_input_device_set_pointer_focus(&wd->input_device, |
| 309 | NULL, time, 0, 0, 0, 0); |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static void |
| 315 | shell_resize(struct wl_client *client, struct wl_resource *resource, |
| 316 | struct wl_resource *surface_resource, |
| 317 | struct wl_resource *input_resource, uint32_t time, uint32_t edges) |
| 318 | { |
| 319 | struct wlsc_input_device *wd = input_resource->data; |
| 320 | struct wlsc_surface *es = surface_resource->data; |
| 321 | |
| 322 | /* FIXME: Reject if fullscreen */ |
| 323 | |
| 324 | if (wlsc_surface_resize(es, wd, time, edges, resource) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 325 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static void |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 329 | shell_set_toplevel(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 330 | struct wl_resource *resource, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 331 | struct wl_resource *surface_resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 332 | |
| 333 | { |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 334 | struct wlsc_surface *es = surface_resource->data; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 335 | struct shell_surface *priv; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 336 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 337 | priv = get_shell_surface(es); |
| 338 | if (priv->type == SHELL_SURFACE_FULLSCREEN) { |
| 339 | es->x = priv->saved_x; |
| 340 | es->y = priv->saved_y; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | wlsc_surface_damage(es); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 344 | priv->type = SHELL_SURFACE_TOPLEVEL; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 345 | es->fullscreen_output = NULL; |
| 346 | } |
| 347 | |
| 348 | static void |
| 349 | shell_set_transient(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 350 | struct wl_resource *resource, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 351 | struct wl_resource *surface_resource, |
| 352 | struct wl_resource *parent_resource, |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 353 | int x, int y, uint32_t flags) |
| 354 | { |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 355 | struct wlsc_surface *es = surface_resource->data; |
| 356 | struct wlsc_surface *pes = parent_resource->data; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 357 | struct shell_surface *priv; |
| 358 | |
| 359 | priv = get_shell_surface(es); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 360 | |
| 361 | /* assign to parents output */ |
| 362 | es->output = pes->output; |
| 363 | |
| 364 | es->x = pes->x + x; |
| 365 | es->y = pes->y + y; |
| 366 | |
| 367 | wlsc_surface_damage(es); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 368 | priv->type = SHELL_SURFACE_TRANSIENT; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static void |
| 372 | shell_set_fullscreen(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 373 | struct wl_resource *resource, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 374 | struct wl_resource *surface_resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 375 | |
| 376 | { |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 377 | struct wlsc_surface *es = surface_resource->data; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 378 | struct wlsc_output *output; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 379 | struct shell_surface *priv; |
| 380 | |
| 381 | priv = get_shell_surface(es); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 382 | |
| 383 | /* FIXME: Fullscreen on first output */ |
| 384 | /* FIXME: Handle output going away */ |
| 385 | output = container_of(es->compositor->output_list.next, |
| 386 | struct wlsc_output, link); |
| 387 | es->output = output; |
| 388 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 389 | priv->saved_x = es->x; |
| 390 | priv->saved_y = es->y; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 391 | es->x = (output->current->width - es->width) / 2; |
| 392 | es->y = (output->current->height - es->height) / 2; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 393 | es->fullscreen_output = output; |
| 394 | wlsc_surface_damage(es); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 395 | priv->type = SHELL_SURFACE_FULLSCREEN; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 399 | destroy_drag(struct wl_resource *resource) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 400 | { |
| 401 | struct wl_drag *drag = |
| 402 | container_of(resource, struct wl_drag, resource); |
| 403 | |
| 404 | wl_list_remove(&drag->drag_focus_listener.link); |
| 405 | if (drag->grab.input_device) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 406 | wl_input_device_end_grab(drag->grab.input_device, |
| 407 | wlsc_compositor_get_time()); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 408 | |
| 409 | free(drag); |
| 410 | } |
| 411 | |
| 412 | |
| 413 | static void |
| 414 | wl_drag_set_pointer_focus(struct wl_drag *drag, |
| 415 | struct wl_surface *surface, uint32_t time, |
| 416 | int32_t x, int32_t y, int32_t sx, int32_t sy) |
| 417 | { |
| 418 | char **p, **end; |
| 419 | |
| 420 | if (drag->drag_focus == surface) |
| 421 | return; |
| 422 | |
| 423 | if (drag->drag_focus && |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 424 | (!surface || |
| 425 | drag->drag_focus->resource.client != surface->resource.client)) |
| 426 | wl_resource_post_event(&drag->drag_offer.resource, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 427 | WL_DRAG_OFFER_POINTER_FOCUS, |
| 428 | time, NULL, 0, 0, 0, 0); |
| 429 | |
| 430 | if (surface && |
| 431 | (!drag->drag_focus || |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 432 | drag->drag_focus->resource.client != surface->resource.client)) { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 433 | |
| 434 | drag->drag_offer.resource.client = surface->resource.client; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 435 | end = drag->types.data + drag->types.size; |
| 436 | for (p = drag->types.data; p < end; p++) |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 437 | wl_resource_post_event(&drag->drag_offer.resource, |
| 438 | WL_DRAG_OFFER_OFFER, *p); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | if (surface) { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 442 | wl_resource_post_event(&drag->drag_offer.resource, |
| 443 | WL_DRAG_OFFER_POINTER_FOCUS, |
| 444 | time, surface, |
| 445 | x, y, sx, sy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 446 | |
| 447 | } |
| 448 | |
| 449 | drag->drag_focus = surface; |
| 450 | drag->pointer_focus_time = time; |
| 451 | drag->target = NULL; |
| 452 | |
| 453 | wl_list_remove(&drag->drag_focus_listener.link); |
| 454 | if (surface) |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 455 | wl_list_insert(surface->resource.destroy_listener_list.prev, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 456 | &drag->drag_focus_listener.link); |
| 457 | } |
| 458 | |
| 459 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 460 | drag_offer_accept(struct wl_client *client, struct wl_resource *resource, |
| 461 | uint32_t time, const char *type) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 462 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 463 | struct wl_drag_offer *offer = resource->data; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 464 | struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer); |
| 465 | char **p, **end; |
| 466 | |
| 467 | /* If the client responds to drag pointer_focus or motion |
| 468 | * events after the pointer has left the surface, we just |
| 469 | * discard the accept requests. The drag source just won't |
| 470 | * get the corresponding 'target' events and eventually the |
| 471 | * next surface/root will start sending events. */ |
| 472 | if (time < drag->pointer_focus_time) |
| 473 | return; |
| 474 | |
| 475 | drag->target = client; |
| 476 | drag->type = NULL; |
| 477 | end = drag->types.data + drag->types.size; |
| 478 | for (p = drag->types.data; p < end; p++) |
| 479 | if (type && strcmp(*p, type) == 0) |
| 480 | drag->type = *p; |
| 481 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 482 | wl_resource_post_event(&drag->resource, WL_DRAG_TARGET, drag->type); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | static void |
| 486 | drag_offer_receive(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 487 | struct wl_resource *resource, int fd) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 488 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 489 | struct wl_drag_offer *offer = resource->data; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 490 | struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer); |
| 491 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 492 | wl_resource_post_event(&drag->resource, WL_DRAG_FINISH, fd); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 493 | close(fd); |
| 494 | } |
| 495 | |
| 496 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 497 | drag_offer_reject(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 498 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 499 | struct wl_drag_offer *offer = resource->data; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 500 | struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer); |
| 501 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 502 | wl_resource_post_event(&drag->resource, WL_DRAG_REJECT); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static const struct wl_drag_offer_interface drag_offer_interface = { |
| 506 | drag_offer_accept, |
| 507 | drag_offer_receive, |
| 508 | drag_offer_reject |
| 509 | }; |
| 510 | |
| 511 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 512 | drag_offer(struct wl_client *client, |
| 513 | struct wl_resource *resource, const char *type) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 514 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 515 | struct wl_drag *drag = resource->data; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 516 | char **p; |
| 517 | |
| 518 | p = wl_array_add(&drag->types, sizeof *p); |
| 519 | if (p) |
| 520 | *p = strdup(type); |
| 521 | if (!p || !*p) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 522 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static void |
| 526 | drag_grab_motion(struct wl_grab *grab, |
| 527 | uint32_t time, int32_t x, int32_t y) |
| 528 | { |
| 529 | struct wl_drag *drag = container_of(grab, struct wl_drag, grab); |
| 530 | struct wlsc_surface *es; |
| 531 | int32_t sx, sy; |
| 532 | |
| 533 | es = pick_surface(grab->input_device, &sx, &sy); |
| 534 | wl_drag_set_pointer_focus(drag, &es->surface, time, x, y, sx, sy); |
| 535 | if (es) |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 536 | wl_resource_post_event(&drag->drag_offer.resource, |
| 537 | WL_DRAG_OFFER_MOTION, |
| 538 | time, x, y, sx, sy); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static void |
| 542 | drag_grab_button(struct wl_grab *grab, |
| 543 | uint32_t time, int32_t button, int32_t state) |
| 544 | { |
| 545 | } |
| 546 | |
| 547 | static void |
| 548 | drag_grab_end(struct wl_grab *grab, uint32_t time) |
| 549 | { |
| 550 | struct wl_drag *drag = container_of(grab, struct wl_drag, grab); |
| 551 | |
| 552 | if (drag->target) |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 553 | wl_resource_post_event(&drag->drag_offer.resource, |
| 554 | WL_DRAG_OFFER_DROP); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 555 | |
| 556 | wl_drag_set_pointer_focus(drag, NULL, time, 0, 0, 0, 0); |
| 557 | } |
| 558 | |
| 559 | static const struct wl_grab_interface drag_grab_interface = { |
| 560 | drag_grab_motion, |
| 561 | drag_grab_button, |
| 562 | drag_grab_end |
| 563 | }; |
| 564 | |
| 565 | static void |
| 566 | drag_activate(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 567 | struct wl_resource *resource, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 568 | struct wl_resource *surface_resource, |
| 569 | struct wl_resource *device_resource, uint32_t time) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 570 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 571 | struct wl_drag *drag = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 572 | struct wl_surface *surface = surface_resource->data; |
| 573 | struct wl_input_device *device = device_resource->data; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 574 | struct wl_display *display = wl_client_get_display (client); |
| 575 | struct wlsc_surface *target; |
| 576 | int32_t sx, sy; |
| 577 | |
| 578 | if (wl_input_device_update_grab(device, |
| 579 | &drag->grab, surface, time) < 0) |
| 580 | return; |
| 581 | |
| 582 | drag->grab.interface = &drag_grab_interface; |
| 583 | |
| 584 | drag->source = surface; |
| 585 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 586 | drag->drag_offer.resource.object.interface = &wl_drag_offer_interface; |
| 587 | drag->drag_offer.resource.object.implementation = |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 588 | (void (**)(void)) &drag_offer_interface; |
| 589 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 590 | wl_display_add_global(display, &wl_drag_offer_interface, drag, NULL); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 591 | |
| 592 | target = pick_surface(device, &sx, &sy); |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 593 | wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 594 | wl_drag_set_pointer_focus(drag, &target->surface, time, |
| 595 | device->x, device->y, sx, sy); |
| 596 | } |
| 597 | |
| 598 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 599 | drag_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 600 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 601 | wl_resource_destroy(resource, wlsc_compositor_get_time()); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static const struct wl_drag_interface drag_interface = { |
| 605 | drag_offer, |
| 606 | drag_activate, |
| 607 | drag_destroy, |
| 608 | }; |
| 609 | |
| 610 | static void |
| 611 | drag_handle_surface_destroy(struct wl_listener *listener, |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 612 | struct wl_resource *resource, uint32_t time) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 613 | { |
| 614 | struct wl_drag *drag = |
| 615 | container_of(listener, struct wl_drag, drag_focus_listener); |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 616 | struct wl_surface *surface = (struct wl_surface *) resource; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 617 | |
| 618 | if (drag->drag_focus == surface) |
| 619 | wl_drag_set_pointer_focus(drag, NULL, time, 0, 0, 0, 0); |
| 620 | } |
| 621 | |
| 622 | static void |
| 623 | shell_create_drag(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 624 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 625 | { |
| 626 | struct wl_drag *drag; |
| 627 | |
| 628 | drag = malloc(sizeof *drag); |
| 629 | if (drag == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 630 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 631 | return; |
| 632 | } |
| 633 | |
| 634 | memset(drag, 0, sizeof *drag); |
| 635 | drag->resource.object.id = id; |
| 636 | drag->resource.object.interface = &wl_drag_interface; |
| 637 | drag->resource.object.implementation = |
| 638 | (void (**)(void)) &drag_interface; |
| 639 | |
Pekka Paalanen | 02ebfb1 | 2011-10-24 17:34:53 +0300 | [diff] [blame] | 640 | drag->resource.data = drag; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 641 | drag->resource.destroy = destroy_drag; |
| 642 | |
| 643 | drag->drag_focus_listener.func = drag_handle_surface_destroy; |
| 644 | wl_list_init(&drag->drag_focus_listener.link); |
| 645 | |
| 646 | wl_client_add_resource(client, &drag->resource); |
| 647 | } |
| 648 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 649 | static void |
| 650 | wlsc_selection_set_focus(struct wlsc_shell *shell, |
| 651 | struct wl_selection *selection, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 652 | struct wl_surface *surface, uint32_t time) |
| 653 | { |
| 654 | char **p, **end; |
| 655 | |
| 656 | if (selection->selection_focus == surface) |
| 657 | return; |
| 658 | |
| 659 | if (selection->selection_focus != NULL) |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 660 | wl_resource_post_event(&selection->selection_offer.resource, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 661 | WL_SELECTION_OFFER_KEYBOARD_FOCUS, |
| 662 | NULL); |
| 663 | |
| 664 | if (surface) { |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 665 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 666 | selection->selection_offer.resource.client = surface->resource.client; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 667 | end = selection->types.data + selection->types.size; |
| 668 | for (p = selection->types.data; p < end; p++) |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 669 | wl_resource_post_event(&selection->selection_offer.resource, |
| 670 | WL_SELECTION_OFFER_OFFER, *p); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 671 | |
| 672 | wl_list_remove(&selection->selection_focus_listener.link); |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 673 | wl_list_insert(surface->resource.destroy_listener_list.prev, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 674 | &selection->selection_focus_listener.link); |
| 675 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 676 | wl_resource_post_event(&selection->selection_offer.resource, |
| 677 | WL_SELECTION_OFFER_KEYBOARD_FOCUS, |
| 678 | selection->input_device); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | selection->selection_focus = surface; |
| 682 | |
| 683 | wl_list_remove(&selection->selection_focus_listener.link); |
| 684 | if (surface) |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 685 | wl_list_insert(surface->resource.destroy_listener_list.prev, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 686 | &selection->selection_focus_listener.link); |
| 687 | } |
| 688 | |
| 689 | static void |
| 690 | selection_offer_receive(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 691 | struct wl_resource *resource, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 692 | const char *mime_type, int fd) |
| 693 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 694 | struct wl_selection_offer *offer = resource->data; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 695 | struct wl_selection *selection = |
| 696 | container_of(offer, struct wl_selection, selection_offer); |
| 697 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 698 | wl_resource_post_event(&selection->resource, |
| 699 | WL_SELECTION_SEND, mime_type, fd); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 700 | close(fd); |
| 701 | } |
| 702 | |
| 703 | static const struct wl_selection_offer_interface selection_offer_interface = { |
| 704 | selection_offer_receive |
| 705 | }; |
| 706 | |
| 707 | static void |
| 708 | selection_offer(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 709 | struct wl_resource *resource, const char *type) |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 710 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 711 | struct wl_selection *selection = resource->data; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 712 | char **p; |
| 713 | |
| 714 | p = wl_array_add(&selection->types, sizeof *p); |
| 715 | if (p) |
| 716 | *p = strdup(type); |
| 717 | if (!p || !*p) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 718 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static void |
| 722 | selection_activate(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 723 | struct wl_resource *resource, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 724 | struct wl_resource *input_resource, uint32_t time) |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 725 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 726 | struct wl_selection *selection = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 727 | struct wlsc_input_device *wd = input_resource->data; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 728 | struct wl_display *display = wl_client_get_display (client); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 729 | struct wlsc_compositor *compositor = wd->compositor; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 730 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 731 | selection->input_device = &wd->input_device; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 732 | |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 733 | selection->selection_offer.resource.object.interface = |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 734 | &wl_selection_offer_interface; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 735 | selection->selection_offer.resource.object.implementation = |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 736 | (void (**)(void)) &selection_offer_interface; |
| 737 | |
Kristian Høgsberg | d9551a3 | 2011-08-19 12:07:44 -0400 | [diff] [blame] | 738 | wl_display_add_global(display, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 739 | &wl_selection_offer_interface, selection, NULL); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 740 | |
| 741 | if (wd->selection) { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 742 | wl_resource_post_event(&wd->selection->resource, |
| 743 | WL_SELECTION_CANCELLED); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 744 | } |
| 745 | wd->selection = selection; |
| 746 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 747 | wlsc_selection_set_focus(compositor->shell, selection, |
| 748 | wd->input_device.keyboard_focus, time); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 752 | selection_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 753 | { |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 754 | wl_resource_destroy(resource, wlsc_compositor_get_time()); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | static const struct wl_selection_interface selection_interface = { |
| 758 | selection_offer, |
| 759 | selection_activate, |
| 760 | selection_destroy |
| 761 | }; |
| 762 | |
| 763 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 764 | destroy_selection(struct wl_resource *resource) |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 765 | { |
| 766 | struct wl_selection *selection = |
| 767 | container_of(resource, struct wl_selection, resource); |
| 768 | struct wlsc_input_device *wd = |
| 769 | (struct wlsc_input_device *) selection->input_device; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 770 | struct wlsc_compositor *compositor = wd->compositor; |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 771 | |
| 772 | if (wd && wd->selection == selection) { |
| 773 | wd->selection = NULL; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 774 | wlsc_selection_set_focus(compositor->shell, |
| 775 | selection, NULL, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 776 | wlsc_compositor_get_time()); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | wl_list_remove(&selection->selection_focus_listener.link); |
| 780 | free(selection); |
| 781 | } |
| 782 | |
| 783 | static void |
| 784 | selection_handle_surface_destroy(struct wl_listener *listener, |
Benjamin Franzke | 4721a3c | 2011-05-06 17:13:17 +0200 | [diff] [blame] | 785 | struct wl_resource *resource, uint32_t time) |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 786 | { |
| 787 | } |
| 788 | |
| 789 | static void |
| 790 | shell_create_selection(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 791 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 792 | { |
| 793 | struct wl_selection *selection; |
| 794 | |
| 795 | selection = malloc(sizeof *selection); |
| 796 | if (selection == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 797 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 798 | return; |
| 799 | } |
| 800 | |
| 801 | memset(selection, 0, sizeof *selection); |
| 802 | selection->resource.object.id = id; |
| 803 | selection->resource.object.interface = &wl_selection_interface; |
| 804 | selection->resource.object.implementation = |
| 805 | (void (**)(void)) &selection_interface; |
| 806 | |
| 807 | selection->client = client; |
| 808 | selection->resource.destroy = destroy_selection; |
| 809 | selection->selection_focus = NULL; |
| 810 | |
| 811 | selection->selection_focus_listener.func = |
| 812 | selection_handle_surface_destroy; |
| 813 | wl_list_init(&selection->selection_focus_listener.link); |
| 814 | |
| 815 | wl_client_add_resource(client, &selection->resource); |
| 816 | } |
| 817 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 818 | static const struct wl_shell_interface shell_interface = { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 819 | shell_move, |
| 820 | shell_resize, |
Kristian Høgsberg | ae6c8a6 | 2011-01-18 09:08:53 -0500 | [diff] [blame] | 821 | shell_create_drag, |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 822 | shell_create_selection, |
| 823 | shell_set_toplevel, |
| 824 | shell_set_transient, |
| 825 | shell_set_fullscreen |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 826 | }; |
| 827 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 828 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 829 | handle_background_surface_destroy(struct wl_listener *listener, |
| 830 | struct wl_resource *resource, uint32_t time) |
| 831 | { |
| 832 | struct wl_shell *shell = |
| 833 | container_of(listener, struct wl_shell, background_listener); |
| 834 | |
| 835 | fprintf(stderr, "background surface gone\n"); |
| 836 | shell->background = NULL; |
| 837 | } |
| 838 | |
| 839 | static void |
| 840 | desktop_shell_set_background(struct wl_client *client, |
| 841 | struct wl_resource *resource, |
| 842 | struct wl_resource *surface_resource) |
| 843 | { |
| 844 | struct wl_shell *shell = resource->data; |
| 845 | struct wlsc_surface *surface = surface_resource->data; |
| 846 | struct wlsc_output *output = |
| 847 | container_of(shell->compositor->output_list.next, |
| 848 | struct wlsc_output, link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 849 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 850 | |
| 851 | shell->background = surface_resource->data; |
| 852 | shell->background_listener.func = handle_background_surface_destroy; |
| 853 | wl_list_insert(&surface_resource->destroy_listener_list, |
| 854 | &shell->background_listener.link); |
| 855 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 856 | priv = get_shell_surface(surface); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 857 | priv->type = SHELL_SURFACE_BACKGROUND; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 858 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 859 | wl_resource_post_event(resource, |
| 860 | DESKTOP_SHELL_CONFIGURE, |
| 861 | wlsc_compositor_get_time(), 0, surface, |
| 862 | output->current->width, |
| 863 | output->current->height); |
| 864 | } |
| 865 | |
| 866 | static void |
| 867 | handle_panel_surface_destroy(struct wl_listener *listener, |
| 868 | struct wl_resource *resource, uint32_t time) |
| 869 | { |
| 870 | struct wl_shell *shell = |
| 871 | container_of(listener, struct wl_shell, panel_listener); |
| 872 | |
| 873 | fprintf(stderr, "panel surface gone\n"); |
| 874 | shell->panel = NULL; |
| 875 | } |
| 876 | |
| 877 | static void |
| 878 | desktop_shell_set_panel(struct wl_client *client, |
| 879 | struct wl_resource *resource, |
| 880 | struct wl_resource *surface_resource) |
| 881 | { |
| 882 | struct wl_shell *shell = resource->data; |
| 883 | struct wlsc_output *output = |
| 884 | container_of(shell->compositor->output_list.next, |
| 885 | struct wlsc_output, link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 886 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 887 | |
| 888 | shell->panel = surface_resource->data; |
| 889 | |
| 890 | shell->panel_listener.func = handle_panel_surface_destroy; |
| 891 | wl_list_insert(&surface_resource->destroy_listener_list, |
| 892 | &shell->panel_listener.link); |
| 893 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 894 | priv = get_shell_surface(shell->panel); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 895 | priv->type = SHELL_SURFACE_PANEL; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 896 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 897 | wl_resource_post_event(resource, |
| 898 | DESKTOP_SHELL_CONFIGURE, |
| 899 | wlsc_compositor_get_time(), 0, surface_resource, |
| 900 | output->current->width, |
| 901 | output->current->height); |
| 902 | } |
| 903 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 904 | static void |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 905 | handle_lock_surface_destroy(struct wl_listener *listener, |
| 906 | struct wl_resource *resource, uint32_t time) |
| 907 | { |
| 908 | struct wl_shell *shell = |
Pekka Paalanen | 2ca8630 | 2011-11-16 13:47:35 +0200 | [diff] [blame] | 909 | container_of(listener, struct wl_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 910 | |
| 911 | fprintf(stderr, "lock surface gone\n"); |
| 912 | shell->lock_surface = NULL; |
| 913 | } |
| 914 | |
| 915 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 916 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 917 | struct wl_resource *resource, |
| 918 | struct wl_resource *surface_resource) |
| 919 | { |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 920 | struct wl_shell *shell = resource->data; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 921 | struct shell_surface *priv; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 922 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 923 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 924 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 925 | if (!shell->locked) |
| 926 | return; |
| 927 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 928 | shell->lock_surface = surface_resource->data; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 929 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 930 | shell->lock_surface_listener.func = handle_lock_surface_destroy; |
| 931 | wl_list_insert(&surface_resource->destroy_listener_list, |
| 932 | &shell->lock_surface_listener.link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 933 | |
| 934 | priv = get_shell_surface(shell->lock_surface); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 935 | priv->type = SHELL_SURFACE_LOCK; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static void |
| 939 | resume_desktop(struct wl_shell *shell) |
| 940 | { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 941 | struct wlsc_surface *surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 942 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 943 | wl_list_for_each(surface, &shell->hidden_surface_list, link) |
| 944 | wlsc_surface_configure(surface, surface->x, surface->y, |
| 945 | surface->width, surface->height); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 946 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 947 | wl_list_insert_list(shell->background->link.prev, |
| 948 | &shell->hidden_surface_list); |
| 949 | wl_list_init(&shell->hidden_surface_list); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 950 | |
| 951 | shell->locked = false; |
| 952 | wlsc_compositor_repick(shell->compositor); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 953 | wlsc_compositor_wake(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | static void |
| 957 | desktop_shell_unlock(struct wl_client *client, |
| 958 | struct wl_resource *resource) |
| 959 | { |
| 960 | struct wl_shell *shell = resource->data; |
| 961 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 962 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 963 | |
| 964 | if (shell->locked) |
| 965 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 966 | } |
| 967 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 968 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 969 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 970 | desktop_shell_set_panel, |
| 971 | desktop_shell_set_lock_surface, |
| 972 | desktop_shell_unlock |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 973 | }; |
| 974 | |
| 975 | static void |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 976 | move_binding(struct wl_input_device *device, uint32_t time, |
| 977 | uint32_t key, uint32_t button, uint32_t state, void *data) |
| 978 | { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 979 | struct wl_shell *shell = data; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 980 | struct wlsc_surface *surface = |
| 981 | (struct wlsc_surface *) device->pointer_focus; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 982 | struct shell_surface *priv; |
| 983 | |
| 984 | priv = get_shell_surface(surface); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 985 | |
Kristian Høgsberg | a4a42f0 | 2011-09-08 16:56:57 -0400 | [diff] [blame] | 986 | if (surface == NULL || |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 987 | priv->type == SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 988 | return; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 989 | if (surface == shell->panel) |
| 990 | return; |
| 991 | if (surface == shell->background) |
| 992 | return; |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 993 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 994 | wlsc_surface_move(surface, (struct wlsc_input_device *) device, time); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | static void |
| 998 | resize_binding(struct wl_input_device *device, uint32_t time, |
| 999 | uint32_t key, uint32_t button, uint32_t state, void *data) |
| 1000 | { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1001 | struct wl_shell *shell = data; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1002 | struct wlsc_surface *surface = |
| 1003 | (struct wlsc_surface *) device->pointer_focus; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1004 | struct wl_resource *resource; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1005 | uint32_t edges = 0; |
| 1006 | int32_t x, y; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1007 | struct shell_surface *priv; |
| 1008 | |
| 1009 | priv = get_shell_surface(surface); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1010 | |
Kristian Høgsberg | a4a42f0 | 2011-09-08 16:56:57 -0400 | [diff] [blame] | 1011 | if (surface == NULL || |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1012 | priv->type == SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1013 | if (surface == shell->panel) |
| 1014 | return; |
| 1015 | if (surface == shell->background) |
| 1016 | return; |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 1017 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1018 | x = device->grab_x - surface->x; |
| 1019 | y = device->grab_y - surface->y; |
| 1020 | |
| 1021 | if (x < surface->width / 3) |
| 1022 | edges |= WL_SHELL_RESIZE_LEFT; |
| 1023 | else if (x < 2 * surface->width / 3) |
| 1024 | edges |= 0; |
| 1025 | else |
| 1026 | edges |= WL_SHELL_RESIZE_RIGHT; |
| 1027 | |
| 1028 | if (y < surface->height / 3) |
| 1029 | edges |= WL_SHELL_RESIZE_TOP; |
| 1030 | else if (y < 2 * surface->height / 3) |
| 1031 | edges |= 0; |
| 1032 | else |
| 1033 | edges |= WL_SHELL_RESIZE_BOTTOM; |
| 1034 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1035 | resource = /* Find shell resource for surface client */ 0; |
| 1036 | |
| 1037 | /* ... or use wl_shell_surface */ |
| 1038 | |
| 1039 | wlsc_surface_resize(surface, (struct wlsc_input_device *) device, |
| 1040 | time, edges, resource); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1044 | activate(struct wlsc_shell *base, struct wlsc_surface *es, |
| 1045 | struct wlsc_input_device *device, uint32_t time) |
| 1046 | { |
| 1047 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 1048 | struct wlsc_compositor *compositor = shell->compositor; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1049 | struct shell_surface *priv; |
| 1050 | |
| 1051 | priv = get_shell_surface(es); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1052 | |
| 1053 | wlsc_surface_activate(es, device, time); |
| 1054 | |
Kristian Høgsberg | d6e5525 | 2011-10-11 23:41:17 -0400 | [diff] [blame] | 1055 | if (compositor->wxs) |
| 1056 | wlsc_xserver_surface_activate(es); |
| 1057 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1058 | switch (priv->type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1059 | case SHELL_SURFACE_BACKGROUND: |
| 1060 | /* put background back to bottom */ |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1061 | wl_list_remove(&es->link); |
| 1062 | wl_list_insert(compositor->surface_list.prev, &es->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1063 | break; |
| 1064 | case SHELL_SURFACE_PANEL: |
| 1065 | /* already put on top */ |
| 1066 | break; |
| 1067 | default: |
| 1068 | if (shell->panel && !shell->locked) { |
| 1069 | /* bring panel back to top */ |
| 1070 | wl_list_remove(&shell->panel->link); |
| 1071 | wl_list_insert(&compositor->surface_list, |
| 1072 | &shell->panel->link); |
| 1073 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1078 | lock(struct wlsc_shell *base) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1079 | { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1080 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1081 | struct wl_list *surface_list = &shell->compositor->surface_list; |
| 1082 | struct wlsc_surface *cur; |
| 1083 | struct wlsc_surface *tmp; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1084 | struct shell_surface *priv; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1085 | struct wlsc_input_device *device; |
| 1086 | uint32_t time; |
| 1087 | |
| 1088 | if (shell->locked) |
| 1089 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1090 | |
| 1091 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1092 | |
| 1093 | /* Move all surfaces from compositor's list to our hidden list, |
| 1094 | * except the background. This way nothing else can show or |
| 1095 | * receive input events while we are locked. */ |
| 1096 | |
| 1097 | if (!wl_list_empty(&shell->hidden_surface_list)) { |
| 1098 | fprintf(stderr, |
| 1099 | "%s: Assertion failed: hidden_surface_list is not empty.\n", |
| 1100 | __func__); |
| 1101 | } |
| 1102 | |
| 1103 | wl_list_for_each_safe(cur, tmp, surface_list, link) { |
| 1104 | /* skip input device sprites, cur->surface is uninitialised */ |
| 1105 | if (cur->surface.resource.client == NULL) |
| 1106 | continue; |
| 1107 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1108 | priv = get_shell_surface(cur); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1109 | if (priv->type == SHELL_SURFACE_BACKGROUND) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1110 | continue; |
| 1111 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1112 | cur->output = NULL; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1113 | wl_list_remove(&cur->link); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1114 | wl_list_insert(shell->hidden_surface_list.prev, &cur->link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | /* reset pointer foci */ |
| 1118 | wlsc_compositor_repick(shell->compositor); |
| 1119 | |
| 1120 | /* reset keyboard foci */ |
| 1121 | time = wlsc_compositor_get_time(); |
| 1122 | wl_list_for_each(device, &shell->compositor->input_device_list, link) { |
| 1123 | wl_input_device_set_keyboard_focus(&device->input_device, |
| 1124 | NULL, time); |
| 1125 | } |
| 1126 | |
| 1127 | /* TODO: disable bindings that should not work while locked. */ |
| 1128 | |
| 1129 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static void |
| 1133 | unlock(struct wlsc_shell *base) |
| 1134 | { |
| 1135 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 1136 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 1137 | if (!shell->locked || shell->lock_surface) { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1138 | wlsc_compositor_wake(shell->compositor); |
| 1139 | return; |
| 1140 | } |
| 1141 | |
| 1142 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 1143 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1144 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1145 | return; |
| 1146 | } |
| 1147 | |
| 1148 | if (shell->prepare_event_sent) |
| 1149 | return; |
| 1150 | |
| 1151 | wl_resource_post_event(shell->child.desktop_shell, |
| 1152 | DESKTOP_SHELL_PREPARE_LOCK_SURFACE); |
| 1153 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | static void |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1157 | map(struct wlsc_shell *base, |
| 1158 | struct wlsc_surface *surface, int32_t width, int32_t height) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1159 | { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1160 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 1161 | struct wlsc_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1162 | struct wl_list *list; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1163 | struct shell_surface *priv; |
| 1164 | |
| 1165 | priv = get_shell_surface(surface); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1166 | |
| 1167 | if (shell->locked) |
| 1168 | list = &shell->hidden_surface_list; |
| 1169 | else |
| 1170 | list = &compositor->surface_list; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1171 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1172 | /* surface stacking order, see also activate() */ |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1173 | switch (priv->type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1174 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1175 | /* background always visible, at the bottom */ |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1176 | wl_list_insert(compositor->surface_list.prev, &surface->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1177 | break; |
| 1178 | case SHELL_SURFACE_PANEL: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1179 | /* panel always on top, hidden while locked */ |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1180 | wl_list_insert(list, &surface->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1181 | break; |
| 1182 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1183 | /* lock surface always visible, on top */ |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1184 | wl_list_insert(&compositor->surface_list, &surface->link); |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1185 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1186 | wlsc_compositor_repick(compositor); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1187 | wlsc_compositor_wake(compositor); |
| 1188 | break; |
| 1189 | default: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 1190 | /* everything else just below the panel */ |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1191 | if (shell->panel) |
| 1192 | wl_list_insert(&shell->panel->link, &surface->link); |
| 1193 | else |
| 1194 | wl_list_insert(list, &surface->link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1195 | } |
| 1196 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1197 | if (priv->type == SHELL_SURFACE_TOPLEVEL) { |
Kristian Høgsberg | 4677013 | 2011-11-09 12:38:53 -0500 | [diff] [blame] | 1198 | surface->x = 10 + random() % 400; |
| 1199 | surface->y = 10 + random() % 400; |
| 1200 | } |
| 1201 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1202 | surface->width = width; |
| 1203 | surface->height = height; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1204 | if (!shell->locked || priv->type == SHELL_SURFACE_LOCK) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1205 | wlsc_surface_configure(surface, |
| 1206 | surface->x, surface->y, width, height); |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | static void |
| 1210 | configure(struct wlsc_shell *shell, struct wlsc_surface *surface, |
| 1211 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 1212 | { |
| 1213 | struct wlsc_mode *current; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1214 | struct shell_surface *priv; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1215 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1216 | priv = get_shell_surface(surface); |
| 1217 | switch (priv->type) { |
| 1218 | case SHELL_SURFACE_FULLSCREEN: |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1219 | current = surface->fullscreen_output->current; |
| 1220 | x = (current->width - surface->width) / 2; |
| 1221 | y = (current->height - surface->height) / 2; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame^] | 1222 | break; |
| 1223 | default: |
| 1224 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1225 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1226 | |
| 1227 | wlsc_surface_configure(surface, x, y, width, height); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1228 | } |
| 1229 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1230 | static void |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1231 | desktop_shell_sigchld(struct wlsc_process *process, int status) |
| 1232 | { |
| 1233 | struct wl_shell *shell = |
| 1234 | container_of(process, struct wl_shell, child.process); |
| 1235 | |
| 1236 | shell->child.process.pid = 0; |
| 1237 | shell->child.client = NULL; /* already destroyed by wayland */ |
| 1238 | } |
| 1239 | |
| 1240 | static int |
| 1241 | launch_desktop_shell_process(struct wl_shell *shell) |
| 1242 | { |
Kristian Høgsberg | c4693c4 | 2011-11-14 14:57:17 -0500 | [diff] [blame] | 1243 | const char *shell_exe = LIBEXECDIR "/wayland-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1244 | struct wlsc_compositor *compositor = shell->compositor; |
| 1245 | char s[32]; |
| 1246 | int sv[2], flags; |
| 1247 | |
| 1248 | if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) { |
| 1249 | fprintf(stderr, "socketpair failed\n"); |
| 1250 | return -1; |
| 1251 | } |
| 1252 | |
| 1253 | shell->child.process.pid = fork(); |
| 1254 | shell->child.process.cleanup = desktop_shell_sigchld; |
| 1255 | |
| 1256 | switch (shell->child.process.pid) { |
| 1257 | case 0: |
| 1258 | /* SOCK_CLOEXEC closes both ends, so we need to unset |
| 1259 | * the flag on the client fd. */ |
| 1260 | flags = fcntl(sv[1], F_GETFD); |
| 1261 | if (flags != -1) |
| 1262 | fcntl(sv[1], F_SETFD, flags & ~FD_CLOEXEC); |
| 1263 | |
| 1264 | snprintf(s, sizeof s, "%d", sv[1]); |
| 1265 | setenv("WAYLAND_SOCKET", s, 1); |
| 1266 | if (execl(shell_exe, shell_exe, NULL) < 0) |
| 1267 | fprintf(stderr, "%s: running '%s' failed: %m\n", |
| 1268 | __func__, shell_exe); |
| 1269 | exit(-1); |
| 1270 | |
| 1271 | default: |
| 1272 | close(sv[1]); |
| 1273 | shell->child.client = |
| 1274 | wl_client_create(compositor->wl_display, sv[0]); |
| 1275 | wlsc_watch_process(&shell->child.process); |
| 1276 | break; |
| 1277 | |
| 1278 | case -1: |
| 1279 | fprintf(stderr, "%s: fork failed: %m\n", __func__); |
| 1280 | return -1; |
| 1281 | } |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1286 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 1287 | { |
| 1288 | struct wl_shell *shell = data; |
| 1289 | |
| 1290 | wl_client_add_object(client, &wl_shell_interface, |
| 1291 | &shell_interface, id, shell); |
| 1292 | } |
| 1293 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1294 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1295 | unbind_desktop_shell(struct wl_resource *resource) |
| 1296 | { |
| 1297 | struct wl_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1298 | |
| 1299 | if (shell->locked) |
| 1300 | resume_desktop(shell); |
| 1301 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1302 | shell->child.desktop_shell = NULL; |
| 1303 | shell->prepare_event_sent = false; |
| 1304 | free(resource); |
| 1305 | } |
| 1306 | |
| 1307 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1308 | bind_desktop_shell(struct wl_client *client, |
| 1309 | void *data, uint32_t version, uint32_t id) |
| 1310 | { |
| 1311 | struct wl_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 1312 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1313 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 1314 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 1315 | &desktop_shell_implementation, |
| 1316 | id, shell); |
| 1317 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1318 | if (client == shell->child.client) { |
| 1319 | resource->destroy = unbind_desktop_shell; |
| 1320 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 1321 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1322 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 1323 | |
| 1324 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1325 | "permission to bind desktop_shell denied"); |
| 1326 | wl_resource_destroy(resource, 0); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1327 | } |
| 1328 | |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 1329 | int |
| 1330 | shell_init(struct wlsc_compositor *ec); |
| 1331 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1332 | WL_EXPORT int |
| 1333 | shell_init(struct wlsc_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1334 | { |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1335 | struct wl_shell *shell; |
| 1336 | |
| 1337 | shell = malloc(sizeof *shell); |
| 1338 | if (shell == NULL) |
| 1339 | return -1; |
| 1340 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 1341 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1342 | shell->compositor = ec; |
| 1343 | shell->shell.activate = activate; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1344 | shell->shell.lock = lock; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1345 | shell->shell.unlock = unlock; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 1346 | shell->shell.map = map; |
| 1347 | shell->shell.configure = configure; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 1348 | shell->shell.set_selection_focus = wlsc_selection_set_focus; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1349 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1350 | wl_list_init(&shell->hidden_surface_list); |
| 1351 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1352 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 1353 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1354 | return -1; |
| 1355 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1356 | if (wl_display_add_global(ec->wl_display, |
| 1357 | &desktop_shell_interface, |
| 1358 | shell, bind_desktop_shell) == NULL) |
| 1359 | return -1; |
| 1360 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 1361 | if (launch_desktop_shell_process(shell) != 0) |
| 1362 | return -1; |
| 1363 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1364 | wlsc_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1365 | move_binding, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1366 | wlsc_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1367 | resize_binding, shell); |
| 1368 | |
| 1369 | ec->shell = &shell->shell; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1370 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1371 | return 0; |
| 1372 | } |