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