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 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 405 | static const struct wl_shell_interface shell_interface = { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 406 | shell_move, |
| 407 | shell_resize, |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 408 | shell_set_toplevel, |
| 409 | shell_set_transient, |
| 410 | shell_set_fullscreen |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 411 | }; |
| 412 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 413 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 414 | desktop_shell_set_background(struct wl_client *client, |
| 415 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 416 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 417 | struct wl_resource *surface_resource) |
| 418 | { |
| 419 | struct wl_shell *shell = resource->data; |
| 420 | struct wlsc_surface *surface = surface_resource->data; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 421 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 422 | |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 423 | wl_list_for_each(priv, &shell->backgrounds, link) { |
| 424 | if (priv->output == output_resource->data) { |
| 425 | priv->surface->output = NULL; |
| 426 | wl_list_remove(&priv->surface->link); |
| 427 | wl_list_remove(&priv->link); |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 432 | priv = get_shell_surface(surface); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 433 | priv->type = SHELL_SURFACE_BACKGROUND; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 434 | priv->output = output_resource->data; |
| 435 | |
| 436 | wl_list_insert(&shell->backgrounds, &priv->link); |
| 437 | |
| 438 | surface->x = priv->output->x; |
| 439 | surface->y = priv->output->y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 440 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 441 | wl_resource_post_event(resource, |
| 442 | DESKTOP_SHELL_CONFIGURE, |
| 443 | wlsc_compositor_get_time(), 0, surface, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 444 | priv->output->current->width, |
| 445 | priv->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | static void |
| 449 | desktop_shell_set_panel(struct wl_client *client, |
| 450 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 451 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 452 | struct wl_resource *surface_resource) |
| 453 | { |
| 454 | struct wl_shell *shell = resource->data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 455 | struct wlsc_surface *surface = surface_resource->data; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 456 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 457 | |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 458 | wl_list_for_each(priv, &shell->panels, link) { |
| 459 | if (priv->output == output_resource->data) { |
| 460 | priv->surface->output = NULL; |
| 461 | wl_list_remove(&priv->surface->link); |
| 462 | wl_list_remove(&priv->link); |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 467 | priv = get_shell_surface(surface); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 468 | priv->type = SHELL_SURFACE_PANEL; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 469 | priv->output = output_resource->data; |
| 470 | |
| 471 | wl_list_insert(&shell->panels, &priv->link); |
| 472 | |
| 473 | surface->x = priv->output->x; |
| 474 | surface->y = priv->output->y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 475 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 476 | wl_resource_post_event(resource, |
| 477 | DESKTOP_SHELL_CONFIGURE, |
| 478 | wlsc_compositor_get_time(), 0, surface_resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 479 | priv->output->current->width, |
| 480 | priv->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 483 | static void |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 484 | handle_lock_surface_destroy(struct wl_listener *listener, |
| 485 | struct wl_resource *resource, uint32_t time) |
| 486 | { |
| 487 | struct wl_shell *shell = |
Pekka Paalanen | 2ca8630 | 2011-11-16 13:47:35 +0200 | [diff] [blame] | 488 | container_of(listener, struct wl_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 489 | |
| 490 | fprintf(stderr, "lock surface gone\n"); |
| 491 | shell->lock_surface = NULL; |
| 492 | } |
| 493 | |
| 494 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 495 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 496 | struct wl_resource *resource, |
| 497 | struct wl_resource *surface_resource) |
| 498 | { |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 499 | struct wl_shell *shell = resource->data; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 500 | struct shell_surface *priv; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 501 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 502 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 503 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 504 | if (!shell->locked) |
| 505 | return; |
| 506 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 507 | shell->lock_surface = surface_resource->data; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 508 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 509 | shell->lock_surface_listener.func = handle_lock_surface_destroy; |
| 510 | wl_list_insert(&surface_resource->destroy_listener_list, |
| 511 | &shell->lock_surface_listener.link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 512 | |
| 513 | priv = get_shell_surface(shell->lock_surface); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 514 | priv->type = SHELL_SURFACE_LOCK; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static void |
| 518 | resume_desktop(struct wl_shell *shell) |
| 519 | { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 520 | struct wlsc_surface *surface; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 521 | struct shell_surface *background; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 522 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 523 | wl_list_for_each(surface, &shell->hidden_surface_list, link) |
| 524 | wlsc_surface_configure(surface, surface->x, surface->y, |
| 525 | surface->width, surface->height); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 526 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 527 | background = container_of(shell->backgrounds.prev, |
| 528 | struct shell_surface, link); |
| 529 | wl_list_insert_list(background->surface->link.prev, |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 530 | &shell->hidden_surface_list); |
| 531 | wl_list_init(&shell->hidden_surface_list); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 532 | |
| 533 | shell->locked = false; |
| 534 | wlsc_compositor_repick(shell->compositor); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 535 | wlsc_compositor_wake(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void |
| 539 | desktop_shell_unlock(struct wl_client *client, |
| 540 | struct wl_resource *resource) |
| 541 | { |
| 542 | struct wl_shell *shell = resource->data; |
| 543 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 544 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 545 | |
| 546 | if (shell->locked) |
| 547 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 550 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 551 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 552 | desktop_shell_set_panel, |
| 553 | desktop_shell_set_lock_surface, |
| 554 | desktop_shell_unlock |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 555 | }; |
| 556 | |
| 557 | static void |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 558 | move_binding(struct wl_input_device *device, uint32_t time, |
| 559 | uint32_t key, uint32_t button, uint32_t state, void *data) |
| 560 | { |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 561 | struct wlsc_surface *surface = |
| 562 | (struct wlsc_surface *) device->pointer_focus; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 563 | struct shell_surface *priv; |
| 564 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 565 | if (surface == NULL) |
| 566 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 567 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 568 | priv = get_shell_surface(surface); |
| 569 | switch (priv->type) { |
| 570 | case SHELL_SURFACE_PANEL: |
| 571 | case SHELL_SURFACE_BACKGROUND: |
| 572 | case SHELL_SURFACE_FULLSCREEN: |
| 573 | return; |
| 574 | default: |
| 575 | break; |
| 576 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 577 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 578 | wlsc_surface_move(surface, (struct wlsc_input_device *) device, time); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static void |
| 582 | resize_binding(struct wl_input_device *device, uint32_t time, |
| 583 | uint32_t key, uint32_t button, uint32_t state, void *data) |
| 584 | { |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 585 | struct wlsc_surface *surface = |
| 586 | (struct wlsc_surface *) device->pointer_focus; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 587 | struct wl_resource *resource; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 588 | uint32_t edges = 0; |
| 589 | int32_t x, y; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 590 | struct shell_surface *priv; |
| 591 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 592 | if (surface == NULL) |
| 593 | return; |
| 594 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 595 | priv = get_shell_surface(surface); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 596 | switch (priv->type) { |
| 597 | case SHELL_SURFACE_PANEL: |
| 598 | case SHELL_SURFACE_BACKGROUND: |
| 599 | case SHELL_SURFACE_FULLSCREEN: |
| 600 | return; |
| 601 | default: |
| 602 | break; |
| 603 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 604 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 605 | x = device->grab_x - surface->x; |
| 606 | y = device->grab_y - surface->y; |
| 607 | |
| 608 | if (x < surface->width / 3) |
| 609 | edges |= WL_SHELL_RESIZE_LEFT; |
| 610 | else if (x < 2 * surface->width / 3) |
| 611 | edges |= 0; |
| 612 | else |
| 613 | edges |= WL_SHELL_RESIZE_RIGHT; |
| 614 | |
| 615 | if (y < surface->height / 3) |
| 616 | edges |= WL_SHELL_RESIZE_TOP; |
| 617 | else if (y < 2 * surface->height / 3) |
| 618 | edges |= 0; |
| 619 | else |
| 620 | edges |= WL_SHELL_RESIZE_BOTTOM; |
| 621 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 622 | resource = /* Find shell resource for surface client */ 0; |
| 623 | |
| 624 | /* ... or use wl_shell_surface */ |
| 625 | |
| 626 | wlsc_surface_resize(surface, (struct wlsc_input_device *) device, |
| 627 | time, edges, resource); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 631 | activate(struct wlsc_shell *base, struct wlsc_surface *es, |
| 632 | struct wlsc_input_device *device, uint32_t time) |
| 633 | { |
| 634 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 635 | struct wlsc_compositor *compositor = shell->compositor; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 636 | struct shell_surface *priv; |
| 637 | |
| 638 | priv = get_shell_surface(es); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 639 | |
| 640 | wlsc_surface_activate(es, device, time); |
| 641 | |
Kristian Høgsberg | d6e5525 | 2011-10-11 23:41:17 -0400 | [diff] [blame] | 642 | if (compositor->wxs) |
| 643 | wlsc_xserver_surface_activate(es); |
| 644 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 645 | switch (priv->type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 646 | case SHELL_SURFACE_BACKGROUND: |
| 647 | /* put background back to bottom */ |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 648 | wl_list_remove(&es->link); |
| 649 | wl_list_insert(compositor->surface_list.prev, &es->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 650 | break; |
| 651 | case SHELL_SURFACE_PANEL: |
| 652 | /* already put on top */ |
| 653 | break; |
| 654 | default: |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 655 | if (!shell->locked) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 656 | /* bring panel back to top */ |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 657 | struct shell_surface *panel; |
| 658 | wl_list_for_each(panel, &shell->panels, link) { |
| 659 | wl_list_remove(&panel->surface->link); |
| 660 | wl_list_insert(&compositor->surface_list, |
| 661 | &panel->surface->link); |
| 662 | } |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 663 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| 667 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 668 | lock(struct wlsc_shell *base) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 669 | { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 670 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 671 | struct wl_list *surface_list = &shell->compositor->surface_list; |
| 672 | struct wlsc_surface *cur; |
| 673 | struct wlsc_surface *tmp; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 674 | struct shell_surface *priv; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 675 | struct wlsc_input_device *device; |
| 676 | uint32_t time; |
| 677 | |
| 678 | if (shell->locked) |
| 679 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 680 | |
| 681 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 682 | |
| 683 | /* Move all surfaces from compositor's list to our hidden list, |
| 684 | * except the background. This way nothing else can show or |
| 685 | * receive input events while we are locked. */ |
| 686 | |
| 687 | if (!wl_list_empty(&shell->hidden_surface_list)) { |
| 688 | fprintf(stderr, |
| 689 | "%s: Assertion failed: hidden_surface_list is not empty.\n", |
| 690 | __func__); |
| 691 | } |
| 692 | |
| 693 | wl_list_for_each_safe(cur, tmp, surface_list, link) { |
| 694 | /* skip input device sprites, cur->surface is uninitialised */ |
| 695 | if (cur->surface.resource.client == NULL) |
| 696 | continue; |
| 697 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 698 | priv = get_shell_surface(cur); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 699 | if (priv->type == SHELL_SURFACE_BACKGROUND) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 700 | continue; |
| 701 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 702 | cur->output = NULL; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 703 | wl_list_remove(&cur->link); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 704 | wl_list_insert(shell->hidden_surface_list.prev, &cur->link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | /* reset pointer foci */ |
| 708 | wlsc_compositor_repick(shell->compositor); |
| 709 | |
| 710 | /* reset keyboard foci */ |
| 711 | time = wlsc_compositor_get_time(); |
| 712 | wl_list_for_each(device, &shell->compositor->input_device_list, link) { |
| 713 | wl_input_device_set_keyboard_focus(&device->input_device, |
| 714 | NULL, time); |
| 715 | } |
| 716 | |
| 717 | /* TODO: disable bindings that should not work while locked. */ |
| 718 | |
| 719 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static void |
| 723 | unlock(struct wlsc_shell *base) |
| 724 | { |
| 725 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 726 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 727 | if (!shell->locked || shell->lock_surface) { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 728 | wlsc_compositor_wake(shell->compositor); |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 733 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 734 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
| 738 | if (shell->prepare_event_sent) |
| 739 | return; |
| 740 | |
| 741 | wl_resource_post_event(shell->child.desktop_shell, |
| 742 | DESKTOP_SHELL_PREPARE_LOCK_SURFACE); |
| 743 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | static void |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 747 | map(struct wlsc_shell *base, |
| 748 | struct wlsc_surface *surface, int32_t width, int32_t height) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 749 | { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 750 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 751 | struct wlsc_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 752 | struct wl_list *list; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 753 | struct shell_surface *priv; |
| 754 | |
| 755 | priv = get_shell_surface(surface); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 756 | |
| 757 | if (shell->locked) |
| 758 | list = &shell->hidden_surface_list; |
| 759 | else |
| 760 | list = &compositor->surface_list; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 761 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 762 | /* surface stacking order, see also activate() */ |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 763 | switch (priv->type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 764 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 765 | /* background always visible, at the bottom */ |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 766 | wl_list_insert(compositor->surface_list.prev, &surface->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 767 | break; |
| 768 | case SHELL_SURFACE_PANEL: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 769 | /* panel always on top, hidden while locked */ |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 770 | wl_list_insert(list, &surface->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 771 | break; |
| 772 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 773 | /* lock surface always visible, on top */ |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 774 | wl_list_insert(&compositor->surface_list, &surface->link); |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 775 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 776 | wlsc_compositor_repick(compositor); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 777 | wlsc_compositor_wake(compositor); |
| 778 | break; |
| 779 | default: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 780 | /* everything else just below the panel */ |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 781 | if (!wl_list_empty(&shell->panels)) { |
| 782 | struct shell_surface *panel = |
| 783 | container_of(shell->panels.prev, |
| 784 | struct shell_surface, link); |
| 785 | wl_list_insert(&panel->surface->link, &surface->link); |
| 786 | } else { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 787 | wl_list_insert(list, &surface->link); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 788 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 789 | } |
| 790 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 791 | if (priv->type == SHELL_SURFACE_TOPLEVEL) { |
Kristian Høgsberg | 4677013 | 2011-11-09 12:38:53 -0500 | [diff] [blame] | 792 | surface->x = 10 + random() % 400; |
| 793 | surface->y = 10 + random() % 400; |
| 794 | } |
| 795 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 796 | surface->width = width; |
| 797 | surface->height = height; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 798 | if (!shell->locked || priv->type == SHELL_SURFACE_LOCK) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 799 | wlsc_surface_configure(surface, |
| 800 | surface->x, surface->y, width, height); |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | static void |
| 804 | configure(struct wlsc_shell *shell, struct wlsc_surface *surface, |
| 805 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 806 | { |
| 807 | struct wlsc_mode *current; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 808 | struct shell_surface *priv; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 809 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 810 | priv = get_shell_surface(surface); |
| 811 | switch (priv->type) { |
| 812 | case SHELL_SURFACE_FULLSCREEN: |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 813 | current = surface->fullscreen_output->current; |
| 814 | x = (current->width - surface->width) / 2; |
| 815 | y = (current->height - surface->height) / 2; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 816 | break; |
| 817 | default: |
| 818 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 819 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 820 | |
| 821 | wlsc_surface_configure(surface, x, y, width, height); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 822 | } |
| 823 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 824 | static void |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 825 | desktop_shell_sigchld(struct wlsc_process *process, int status) |
| 826 | { |
| 827 | struct wl_shell *shell = |
| 828 | container_of(process, struct wl_shell, child.process); |
| 829 | |
| 830 | shell->child.process.pid = 0; |
| 831 | shell->child.client = NULL; /* already destroyed by wayland */ |
| 832 | } |
| 833 | |
| 834 | static int |
| 835 | launch_desktop_shell_process(struct wl_shell *shell) |
| 836 | { |
Kristian Høgsberg | c4693c4 | 2011-11-14 14:57:17 -0500 | [diff] [blame] | 837 | const char *shell_exe = LIBEXECDIR "/wayland-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 838 | struct wlsc_compositor *compositor = shell->compositor; |
| 839 | char s[32]; |
| 840 | int sv[2], flags; |
| 841 | |
| 842 | if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) { |
| 843 | fprintf(stderr, "socketpair failed\n"); |
| 844 | return -1; |
| 845 | } |
| 846 | |
| 847 | shell->child.process.pid = fork(); |
| 848 | shell->child.process.cleanup = desktop_shell_sigchld; |
| 849 | |
| 850 | switch (shell->child.process.pid) { |
| 851 | case 0: |
| 852 | /* SOCK_CLOEXEC closes both ends, so we need to unset |
| 853 | * the flag on the client fd. */ |
| 854 | flags = fcntl(sv[1], F_GETFD); |
| 855 | if (flags != -1) |
| 856 | fcntl(sv[1], F_SETFD, flags & ~FD_CLOEXEC); |
| 857 | |
| 858 | snprintf(s, sizeof s, "%d", sv[1]); |
| 859 | setenv("WAYLAND_SOCKET", s, 1); |
| 860 | if (execl(shell_exe, shell_exe, NULL) < 0) |
| 861 | fprintf(stderr, "%s: running '%s' failed: %m\n", |
| 862 | __func__, shell_exe); |
| 863 | exit(-1); |
| 864 | |
| 865 | default: |
| 866 | close(sv[1]); |
| 867 | shell->child.client = |
| 868 | wl_client_create(compositor->wl_display, sv[0]); |
| 869 | wlsc_watch_process(&shell->child.process); |
| 870 | break; |
| 871 | |
| 872 | case -1: |
| 873 | fprintf(stderr, "%s: fork failed: %m\n", __func__); |
| 874 | return -1; |
| 875 | } |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 880 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 881 | { |
| 882 | struct wl_shell *shell = data; |
| 883 | |
| 884 | wl_client_add_object(client, &wl_shell_interface, |
| 885 | &shell_interface, id, shell); |
| 886 | } |
| 887 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 888 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 889 | unbind_desktop_shell(struct wl_resource *resource) |
| 890 | { |
| 891 | struct wl_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 892 | |
| 893 | if (shell->locked) |
| 894 | resume_desktop(shell); |
| 895 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 896 | shell->child.desktop_shell = NULL; |
| 897 | shell->prepare_event_sent = false; |
| 898 | free(resource); |
| 899 | } |
| 900 | |
| 901 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 902 | bind_desktop_shell(struct wl_client *client, |
| 903 | void *data, uint32_t version, uint32_t id) |
| 904 | { |
| 905 | struct wl_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 906 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 907 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 908 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 909 | &desktop_shell_implementation, |
| 910 | id, shell); |
| 911 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 912 | if (client == shell->child.client) { |
| 913 | resource->destroy = unbind_desktop_shell; |
| 914 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 915 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 916 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 917 | |
| 918 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 919 | "permission to bind desktop_shell denied"); |
| 920 | wl_resource_destroy(resource, 0); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 921 | } |
| 922 | |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 923 | int |
| 924 | shell_init(struct wlsc_compositor *ec); |
| 925 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 926 | WL_EXPORT int |
| 927 | shell_init(struct wlsc_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 928 | { |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 929 | struct wl_shell *shell; |
| 930 | |
| 931 | shell = malloc(sizeof *shell); |
| 932 | if (shell == NULL) |
| 933 | return -1; |
| 934 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 935 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 936 | shell->compositor = ec; |
| 937 | shell->shell.activate = activate; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 938 | shell->shell.lock = lock; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 939 | shell->shell.unlock = unlock; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 940 | shell->shell.map = map; |
| 941 | shell->shell.configure = configure; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 942 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 943 | wl_list_init(&shell->hidden_surface_list); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 944 | wl_list_init(&shell->backgrounds); |
| 945 | wl_list_init(&shell->panels); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 946 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 947 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 948 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 949 | return -1; |
| 950 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 951 | if (wl_display_add_global(ec->wl_display, |
| 952 | &desktop_shell_interface, |
| 953 | shell, bind_desktop_shell) == NULL) |
| 954 | return -1; |
| 955 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 956 | if (launch_desktop_shell_process(shell) != 0) |
| 957 | return -1; |
| 958 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 959 | wlsc_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 960 | move_binding, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 961 | wlsc_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 962 | resize_binding, shell); |
| 963 | |
| 964 | ec->shell = &shell->shell; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 965 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 966 | return 0; |
| 967 | } |