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 { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 73 | struct wl_resource resource; |
| 74 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 75 | struct wlsc_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 76 | struct wl_listener surface_destroy_listener; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 77 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 78 | enum shell_surface_type type; |
| 79 | int32_t saved_x, saved_y; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 80 | |
| 81 | struct wlsc_output *output; |
| 82 | struct wl_list link; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 85 | struct wlsc_move_grab { |
| 86 | struct wl_grab grab; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 87 | struct wlsc_surface *surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 88 | int32_t dx, dy; |
| 89 | }; |
| 90 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 91 | static struct shell_surface * |
| 92 | get_shell_surface(struct wlsc_surface *surface) |
| 93 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 94 | return surface->shell_priv; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static void |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 98 | move_grab_motion(struct wl_grab *grab, |
| 99 | uint32_t time, int32_t x, int32_t y) |
| 100 | { |
| 101 | struct wlsc_move_grab *move = (struct wlsc_move_grab *) grab; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 102 | struct wlsc_surface *es = move->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 103 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 104 | wlsc_surface_configure(es, x + move->dx, y + move->dy, |
| 105 | es->width, es->height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static void |
| 109 | move_grab_button(struct wl_grab *grab, |
| 110 | uint32_t time, int32_t button, int32_t state) |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | static void |
| 115 | move_grab_end(struct wl_grab *grab, uint32_t time) |
| 116 | { |
| 117 | free(grab); |
| 118 | } |
| 119 | |
| 120 | static const struct wl_grab_interface move_grab_interface = { |
| 121 | move_grab_motion, |
| 122 | move_grab_button, |
| 123 | move_grab_end |
| 124 | }; |
| 125 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 126 | static int |
| 127 | wlsc_surface_move(struct wlsc_surface *es, |
| 128 | struct wlsc_input_device *wd, uint32_t time) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 129 | { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 130 | struct wlsc_move_grab *move; |
| 131 | |
| 132 | move = malloc(sizeof *move); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 133 | if (!move) |
| 134 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 135 | |
| 136 | move->grab.interface = &move_grab_interface; |
| 137 | move->dx = es->x - wd->input_device.grab_x; |
| 138 | move->dy = es->y - wd->input_device.grab_y; |
Kristian Høgsberg | dd4046a | 2011-01-21 17:00:09 -0500 | [diff] [blame] | 139 | move->surface = es; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 140 | |
| 141 | if (wl_input_device_update_grab(&wd->input_device, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 142 | &move->grab, &es->surface, time) < 0) |
| 143 | return 0; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 144 | |
| 145 | wlsc_input_device_set_pointer_image(wd, WLSC_POINTER_DRAGGING); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 146 | wl_input_device_set_pointer_focus(&wd->input_device, |
| 147 | NULL, time, 0, 0, 0, 0); |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 153 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
| 154 | struct wl_resource *input_resource, uint32_t time) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 155 | { |
| 156 | struct wlsc_input_device *wd = input_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 157 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 158 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 159 | if (wlsc_surface_move(shsurf->surface, wd, time) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 160 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | struct wlsc_resize_grab { |
| 164 | struct wl_grab grab; |
| 165 | uint32_t edges; |
| 166 | int32_t dx, dy, width, height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 167 | struct shell_surface *shsurf; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | static void |
| 171 | resize_grab_motion(struct wl_grab *grab, |
| 172 | uint32_t time, int32_t x, int32_t y) |
| 173 | { |
| 174 | struct wlsc_resize_grab *resize = (struct wlsc_resize_grab *) grab; |
| 175 | struct wl_input_device *device = grab->input_device; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 176 | int32_t width, height; |
| 177 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 178 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 179 | width = device->grab_x - x + resize->width; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 180 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 181 | width = x - device->grab_x + resize->width; |
| 182 | } else { |
| 183 | width = resize->width; |
| 184 | } |
| 185 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 186 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 187 | height = device->grab_y - y + resize->height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 188 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 189 | height = y - device->grab_y + resize->height; |
| 190 | } else { |
| 191 | height = resize->height; |
| 192 | } |
| 193 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 194 | wl_resource_post_event(&resize->shsurf->resource, |
| 195 | WL_SHELL_SURFACE_CONFIGURE, time, resize->edges, |
| 196 | width, height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static void |
| 200 | resize_grab_button(struct wl_grab *grab, |
| 201 | uint32_t time, int32_t button, int32_t state) |
| 202 | { |
| 203 | } |
| 204 | |
| 205 | static void |
| 206 | resize_grab_end(struct wl_grab *grab, uint32_t time) |
| 207 | { |
| 208 | free(grab); |
| 209 | } |
| 210 | |
| 211 | static const struct wl_grab_interface resize_grab_interface = { |
| 212 | resize_grab_motion, |
| 213 | resize_grab_button, |
| 214 | resize_grab_end |
| 215 | }; |
| 216 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 217 | static int |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 218 | wlsc_surface_resize(struct shell_surface *shsurf, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 219 | struct wlsc_input_device *wd, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 220 | uint32_t time, uint32_t edges) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 221 | { |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 222 | struct wlsc_resize_grab *resize; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 223 | struct wlsc_surface *es = shsurf->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 224 | enum wlsc_pointer_type pointer = WLSC_POINTER_LEFT_PTR; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 225 | |
Kristian Høgsberg | 0ce2457 | 2011-01-28 15:18:33 -0500 | [diff] [blame] | 226 | /* FIXME: Reject if fullscreen */ |
| 227 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 228 | resize = malloc(sizeof *resize); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 229 | if (!resize) |
| 230 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 231 | |
| 232 | resize->grab.interface = &resize_grab_interface; |
| 233 | resize->edges = edges; |
| 234 | resize->dx = es->x - wd->input_device.grab_x; |
| 235 | resize->dy = es->y - wd->input_device.grab_y; |
| 236 | resize->width = es->width; |
| 237 | resize->height = es->height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 238 | resize->shsurf = shsurf; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 239 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 240 | if (edges == 0 || edges > 15 || |
| 241 | (edges & 3) == 3 || (edges & 12) == 12) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 242 | return 0; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 243 | |
| 244 | switch (edges) { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 245 | case WL_SHELL_SURFACE_RESIZE_TOP: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 246 | pointer = WLSC_POINTER_TOP; |
| 247 | break; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 248 | case WL_SHELL_SURFACE_RESIZE_BOTTOM: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 249 | pointer = WLSC_POINTER_BOTTOM; |
| 250 | break; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 251 | case WL_SHELL_SURFACE_RESIZE_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 252 | pointer = WLSC_POINTER_LEFT; |
| 253 | break; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 254 | case WL_SHELL_SURFACE_RESIZE_TOP_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 255 | pointer = WLSC_POINTER_TOP_LEFT; |
| 256 | break; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 257 | case WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 258 | pointer = WLSC_POINTER_BOTTOM_LEFT; |
| 259 | break; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 260 | case WL_SHELL_SURFACE_RESIZE_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 261 | pointer = WLSC_POINTER_RIGHT; |
| 262 | break; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 263 | case WL_SHELL_SURFACE_RESIZE_TOP_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 264 | pointer = WLSC_POINTER_TOP_RIGHT; |
| 265 | break; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 266 | case WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT: |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 267 | pointer = WLSC_POINTER_BOTTOM_RIGHT; |
| 268 | break; |
| 269 | } |
| 270 | |
| 271 | if (wl_input_device_update_grab(&wd->input_device, |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 272 | &resize->grab, &es->surface, time) < 0) |
| 273 | return 0; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 274 | |
| 275 | wlsc_input_device_set_pointer_image(wd, pointer); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 276 | wl_input_device_set_pointer_focus(&wd->input_device, |
| 277 | NULL, time, 0, 0, 0, 0); |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 283 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
| 284 | struct wl_resource *input_resource, uint32_t time, |
| 285 | uint32_t edges) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 286 | { |
| 287 | struct wlsc_input_device *wd = input_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 288 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 289 | |
| 290 | /* FIXME: Reject if fullscreen */ |
| 291 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 292 | if (wlsc_surface_resize(shsurf, wd, time, edges) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 293 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 297 | shell_surface_set_toplevel(struct wl_client *client, |
| 298 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 299 | |
| 300 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 301 | struct shell_surface *shsurf = resource->data; |
| 302 | struct wlsc_surface *es = shsurf->surface; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 303 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 304 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) { |
| 305 | es->x = shsurf->saved_x; |
| 306 | es->y = shsurf->saved_y; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | wlsc_surface_damage(es); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 310 | shsurf->type = SHELL_SURFACE_TOPLEVEL; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 311 | es->fullscreen_output = NULL; |
| 312 | } |
| 313 | |
| 314 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 315 | shell_surface_set_transient(struct wl_client *client, |
| 316 | struct wl_resource *resource, |
| 317 | struct wl_resource *parent_resource, |
| 318 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 319 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 320 | struct shell_surface *shsurf = resource->data; |
| 321 | struct wlsc_surface *es = shsurf->surface; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 322 | struct wlsc_surface *pes = parent_resource->data; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 323 | |
| 324 | /* assign to parents output */ |
| 325 | es->output = pes->output; |
| 326 | |
| 327 | es->x = pes->x + x; |
| 328 | es->y = pes->y + y; |
| 329 | |
| 330 | wlsc_surface_damage(es); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 331 | shsurf->type = SHELL_SURFACE_TRANSIENT; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 335 | shell_surface_set_fullscreen(struct wl_client *client, |
| 336 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 337 | |
| 338 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 339 | struct shell_surface *shsurf = resource->data; |
| 340 | struct wlsc_surface *es = shsurf->surface; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 341 | struct wlsc_output *output; |
| 342 | |
| 343 | /* FIXME: Fullscreen on first output */ |
| 344 | /* FIXME: Handle output going away */ |
| 345 | output = container_of(es->compositor->output_list.next, |
| 346 | struct wlsc_output, link); |
| 347 | es->output = output; |
| 348 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 349 | shsurf->saved_x = es->x; |
| 350 | shsurf->saved_y = es->y; |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 351 | es->x = (output->current->width - es->width) / 2; |
| 352 | es->y = (output->current->height - es->height) / 2; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 353 | es->fullscreen_output = output; |
| 354 | wlsc_surface_damage(es); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 355 | shsurf->type = SHELL_SURFACE_FULLSCREEN; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 356 | } |
| 357 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 358 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
| 359 | shell_surface_move, |
| 360 | shell_surface_resize, |
| 361 | shell_surface_set_toplevel, |
| 362 | shell_surface_set_transient, |
| 363 | shell_surface_set_fullscreen |
| 364 | }; |
| 365 | |
| 366 | static void |
| 367 | destroy_shell_surface(struct wl_resource *resource) |
| 368 | { |
| 369 | struct shell_surface *shsurf = resource->data; |
| 370 | |
| 371 | /* in case cleaning up a dead client destroys shell_surface first */ |
| 372 | if (shsurf->surface) |
| 373 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 374 | |
| 375 | wl_list_remove(&shsurf->link); |
| 376 | free(shsurf); |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | shell_handle_surface_destroy(struct wl_listener *listener, |
| 381 | struct wl_resource *resource, uint32_t time) |
| 382 | { |
| 383 | struct shell_surface *shsurf = container_of(listener, |
| 384 | struct shell_surface, |
| 385 | surface_destroy_listener); |
| 386 | |
| 387 | shsurf->surface = NULL; |
| 388 | wl_resource_destroy(&shsurf->resource, time); |
| 389 | } |
| 390 | |
| 391 | static void |
| 392 | shell_create_shell_surface(struct wl_client *client, |
| 393 | struct wl_resource *resource, |
| 394 | uint32_t id, |
| 395 | struct wl_resource *surface_resource) |
| 396 | { |
| 397 | struct wlsc_surface *surface = surface_resource->data; |
| 398 | struct shell_surface *shsurf; |
| 399 | |
| 400 | shsurf = calloc(1, sizeof *shsurf); |
| 401 | if (!shsurf) { |
| 402 | wl_resource_post_no_memory(resource); |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | shsurf->resource.destroy = destroy_shell_surface; |
| 407 | shsurf->resource.object.id = id; |
| 408 | shsurf->resource.object.interface = &wl_shell_surface_interface; |
| 409 | shsurf->resource.object.implementation = |
| 410 | (void (**)(void)) &shell_surface_implementation; |
| 411 | shsurf->resource.data = shsurf; |
| 412 | |
| 413 | shsurf->surface = surface; |
| 414 | shsurf->surface_destroy_listener.func = shell_handle_surface_destroy; |
| 415 | wl_list_insert(surface->surface.resource.destroy_listener_list.prev, |
| 416 | &shsurf->surface_destroy_listener.link); |
| 417 | |
| 418 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 419 | wl_list_init(&shsurf->link); |
| 420 | |
| 421 | shsurf->type = SHELL_SURFACE_NORMAL; |
| 422 | |
| 423 | surface->shell_priv = shsurf; |
| 424 | |
| 425 | wl_client_add_resource(client, &shsurf->resource); |
| 426 | } |
| 427 | |
| 428 | static const struct wl_shell_interface shell_implementation = { |
| 429 | shell_create_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 430 | }; |
| 431 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 432 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 433 | desktop_shell_set_background(struct wl_client *client, |
| 434 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 435 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 436 | struct wl_resource *surface_resource) |
| 437 | { |
| 438 | struct wl_shell *shell = resource->data; |
| 439 | struct wlsc_surface *surface = surface_resource->data; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 440 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 441 | |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 442 | wl_list_for_each(priv, &shell->backgrounds, link) { |
| 443 | if (priv->output == output_resource->data) { |
| 444 | priv->surface->output = NULL; |
| 445 | wl_list_remove(&priv->surface->link); |
| 446 | wl_list_remove(&priv->link); |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 451 | priv = get_shell_surface(surface); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 452 | priv->type = SHELL_SURFACE_BACKGROUND; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 453 | priv->output = output_resource->data; |
| 454 | |
| 455 | wl_list_insert(&shell->backgrounds, &priv->link); |
| 456 | |
| 457 | surface->x = priv->output->x; |
| 458 | surface->y = priv->output->y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 459 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 460 | wl_resource_post_event(resource, |
| 461 | DESKTOP_SHELL_CONFIGURE, |
| 462 | wlsc_compositor_get_time(), 0, surface, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 463 | priv->output->current->width, |
| 464 | priv->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | static void |
| 468 | desktop_shell_set_panel(struct wl_client *client, |
| 469 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 470 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 471 | struct wl_resource *surface_resource) |
| 472 | { |
| 473 | struct wl_shell *shell = resource->data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 474 | struct wlsc_surface *surface = surface_resource->data; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 475 | struct shell_surface *priv; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 476 | |
Benjamin Franzke | f02bb64 | 2011-11-23 20:46:40 +0100 | [diff] [blame] | 477 | wl_list_for_each(priv, &shell->panels, link) { |
| 478 | if (priv->output == output_resource->data) { |
| 479 | priv->surface->output = NULL; |
| 480 | wl_list_remove(&priv->surface->link); |
| 481 | wl_list_remove(&priv->link); |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 486 | priv = get_shell_surface(surface); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 487 | priv->type = SHELL_SURFACE_PANEL; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 488 | priv->output = output_resource->data; |
| 489 | |
| 490 | wl_list_insert(&shell->panels, &priv->link); |
| 491 | |
| 492 | surface->x = priv->output->x; |
| 493 | surface->y = priv->output->y; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 494 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 495 | wl_resource_post_event(resource, |
| 496 | DESKTOP_SHELL_CONFIGURE, |
| 497 | wlsc_compositor_get_time(), 0, surface_resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 498 | priv->output->current->width, |
| 499 | priv->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 500 | } |
| 501 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 502 | static void |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 503 | handle_lock_surface_destroy(struct wl_listener *listener, |
| 504 | struct wl_resource *resource, uint32_t time) |
| 505 | { |
| 506 | struct wl_shell *shell = |
Pekka Paalanen | 2ca8630 | 2011-11-16 13:47:35 +0200 | [diff] [blame] | 507 | container_of(listener, struct wl_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 508 | |
| 509 | fprintf(stderr, "lock surface gone\n"); |
| 510 | shell->lock_surface = NULL; |
| 511 | } |
| 512 | |
| 513 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 514 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 515 | struct wl_resource *resource, |
| 516 | struct wl_resource *surface_resource) |
| 517 | { |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 518 | struct wl_shell *shell = resource->data; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 519 | struct shell_surface *priv; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 520 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 521 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 522 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 523 | if (!shell->locked) |
| 524 | return; |
| 525 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 526 | shell->lock_surface = surface_resource->data; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 527 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 528 | shell->lock_surface_listener.func = handle_lock_surface_destroy; |
| 529 | wl_list_insert(&surface_resource->destroy_listener_list, |
| 530 | &shell->lock_surface_listener.link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 531 | |
| 532 | priv = get_shell_surface(shell->lock_surface); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 533 | priv->type = SHELL_SURFACE_LOCK; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static void |
| 537 | resume_desktop(struct wl_shell *shell) |
| 538 | { |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 539 | struct wlsc_surface *surface; |
Pekka Paalanen | fe34083 | 2011-11-25 16:07:52 +0200 | [diff] [blame] | 540 | struct wl_list *list; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 541 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 542 | wl_list_for_each(surface, &shell->hidden_surface_list, link) |
| 543 | wlsc_surface_configure(surface, surface->x, surface->y, |
| 544 | surface->width, surface->height); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 545 | |
Pekka Paalanen | fe34083 | 2011-11-25 16:07:52 +0200 | [diff] [blame] | 546 | if (wl_list_empty(&shell->backgrounds)) { |
| 547 | list = &shell->compositor->surface_list; |
| 548 | } else { |
| 549 | struct shell_surface *background; |
| 550 | background = container_of(shell->backgrounds.prev, |
| 551 | struct shell_surface, link); |
| 552 | list = background->surface->link.prev; |
| 553 | } |
| 554 | |
| 555 | if (!wl_list_empty(&shell->hidden_surface_list)) |
| 556 | wl_list_insert_list(list, &shell->hidden_surface_list); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 557 | wl_list_init(&shell->hidden_surface_list); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 558 | |
| 559 | shell->locked = false; |
| 560 | wlsc_compositor_repick(shell->compositor); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 561 | wlsc_compositor_wake(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static void |
| 565 | desktop_shell_unlock(struct wl_client *client, |
| 566 | struct wl_resource *resource) |
| 567 | { |
| 568 | struct wl_shell *shell = resource->data; |
| 569 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 570 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 571 | |
| 572 | if (shell->locked) |
| 573 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 574 | } |
| 575 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 576 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 577 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 578 | desktop_shell_set_panel, |
| 579 | desktop_shell_set_lock_surface, |
| 580 | desktop_shell_unlock |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 581 | }; |
| 582 | |
| 583 | static void |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 584 | move_binding(struct wl_input_device *device, uint32_t time, |
| 585 | uint32_t key, uint32_t button, uint32_t state, void *data) |
| 586 | { |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 587 | struct wlsc_surface *surface = |
| 588 | (struct wlsc_surface *) device->pointer_focus; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 589 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 590 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 591 | if (surface == NULL) |
| 592 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 593 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 594 | shsurf = get_shell_surface(surface); |
| 595 | switch (shsurf->type) { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 596 | case SHELL_SURFACE_PANEL: |
| 597 | case SHELL_SURFACE_BACKGROUND: |
| 598 | case SHELL_SURFACE_FULLSCREEN: |
| 599 | return; |
| 600 | default: |
| 601 | break; |
| 602 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 603 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 604 | wlsc_surface_move(surface, (struct wlsc_input_device *) device, time); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static void |
| 608 | resize_binding(struct wl_input_device *device, uint32_t time, |
| 609 | uint32_t key, uint32_t button, uint32_t state, void *data) |
| 610 | { |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 611 | struct wlsc_surface *surface = |
| 612 | (struct wlsc_surface *) device->pointer_focus; |
| 613 | uint32_t edges = 0; |
| 614 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 615 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 616 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 617 | if (surface == NULL) |
| 618 | return; |
| 619 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 620 | shsurf = get_shell_surface(surface); |
| 621 | switch (shsurf->type) { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 622 | case SHELL_SURFACE_PANEL: |
| 623 | case SHELL_SURFACE_BACKGROUND: |
| 624 | case SHELL_SURFACE_FULLSCREEN: |
| 625 | return; |
| 626 | default: |
| 627 | break; |
| 628 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 629 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 630 | x = device->grab_x - surface->x; |
| 631 | y = device->grab_y - surface->y; |
| 632 | |
| 633 | if (x < surface->width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 634 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 635 | else if (x < 2 * surface->width / 3) |
| 636 | edges |= 0; |
| 637 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 638 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 639 | |
| 640 | if (y < surface->height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 641 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 642 | else if (y < 2 * surface->height / 3) |
| 643 | edges |= 0; |
| 644 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 645 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 646 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 647 | wlsc_surface_resize(shsurf, (struct wlsc_input_device *) device, |
| 648 | time, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 652 | activate(struct wlsc_shell *base, struct wlsc_surface *es, |
| 653 | struct wlsc_input_device *device, uint32_t time) |
| 654 | { |
| 655 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 656 | struct wlsc_compositor *compositor = shell->compositor; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 657 | struct shell_surface *priv; |
| 658 | |
| 659 | priv = get_shell_surface(es); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 660 | |
| 661 | wlsc_surface_activate(es, device, time); |
| 662 | |
Kristian Høgsberg | d6e5525 | 2011-10-11 23:41:17 -0400 | [diff] [blame] | 663 | if (compositor->wxs) |
| 664 | wlsc_xserver_surface_activate(es); |
| 665 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 666 | switch (priv->type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 667 | case SHELL_SURFACE_BACKGROUND: |
| 668 | /* put background back to bottom */ |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 669 | wl_list_remove(&es->link); |
| 670 | wl_list_insert(compositor->surface_list.prev, &es->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 671 | break; |
| 672 | case SHELL_SURFACE_PANEL: |
| 673 | /* already put on top */ |
| 674 | break; |
| 675 | default: |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 676 | if (!shell->locked) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 677 | /* bring panel back to top */ |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 678 | struct shell_surface *panel; |
| 679 | wl_list_for_each(panel, &shell->panels, link) { |
| 680 | wl_list_remove(&panel->surface->link); |
| 681 | wl_list_insert(&compositor->surface_list, |
| 682 | &panel->surface->link); |
| 683 | } |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 684 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
| 688 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 689 | lock(struct wlsc_shell *base) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 690 | { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 691 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 692 | struct wl_list *surface_list = &shell->compositor->surface_list; |
| 693 | struct wlsc_surface *cur; |
| 694 | struct wlsc_surface *tmp; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 695 | struct shell_surface *priv; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 696 | struct wlsc_input_device *device; |
| 697 | uint32_t time; |
| 698 | |
| 699 | if (shell->locked) |
| 700 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 701 | |
| 702 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 703 | |
| 704 | /* Move all surfaces from compositor's list to our hidden list, |
| 705 | * except the background. This way nothing else can show or |
| 706 | * receive input events while we are locked. */ |
| 707 | |
| 708 | if (!wl_list_empty(&shell->hidden_surface_list)) { |
| 709 | fprintf(stderr, |
| 710 | "%s: Assertion failed: hidden_surface_list is not empty.\n", |
| 711 | __func__); |
| 712 | } |
| 713 | |
| 714 | wl_list_for_each_safe(cur, tmp, surface_list, link) { |
| 715 | /* skip input device sprites, cur->surface is uninitialised */ |
| 716 | if (cur->surface.resource.client == NULL) |
| 717 | continue; |
| 718 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 719 | priv = get_shell_surface(cur); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 720 | if (priv->type == SHELL_SURFACE_BACKGROUND) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 721 | continue; |
| 722 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 723 | cur->output = NULL; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 724 | wl_list_remove(&cur->link); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 725 | wl_list_insert(shell->hidden_surface_list.prev, &cur->link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /* reset pointer foci */ |
| 729 | wlsc_compositor_repick(shell->compositor); |
| 730 | |
| 731 | /* reset keyboard foci */ |
| 732 | time = wlsc_compositor_get_time(); |
| 733 | wl_list_for_each(device, &shell->compositor->input_device_list, link) { |
| 734 | wl_input_device_set_keyboard_focus(&device->input_device, |
| 735 | NULL, time); |
| 736 | } |
| 737 | |
| 738 | /* TODO: disable bindings that should not work while locked. */ |
| 739 | |
| 740 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | static void |
| 744 | unlock(struct wlsc_shell *base) |
| 745 | { |
| 746 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 747 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 748 | if (!shell->locked || shell->lock_surface) { |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 749 | wlsc_compositor_wake(shell->compositor); |
| 750 | return; |
| 751 | } |
| 752 | |
| 753 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 754 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 755 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 756 | return; |
| 757 | } |
| 758 | |
| 759 | if (shell->prepare_event_sent) |
| 760 | return; |
| 761 | |
| 762 | wl_resource_post_event(shell->child.desktop_shell, |
| 763 | DESKTOP_SHELL_PREPARE_LOCK_SURFACE); |
| 764 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static void |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 768 | map(struct wlsc_shell *base, |
| 769 | struct wlsc_surface *surface, int32_t width, int32_t height) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 770 | { |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 771 | struct wl_shell *shell = container_of(base, struct wl_shell, shell); |
| 772 | struct wlsc_compositor *compositor = shell->compositor; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 773 | struct wl_list *list; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 774 | struct shell_surface *priv; |
| 775 | |
| 776 | priv = get_shell_surface(surface); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 777 | |
| 778 | if (shell->locked) |
| 779 | list = &shell->hidden_surface_list; |
| 780 | else |
| 781 | list = &compositor->surface_list; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 782 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 783 | /* surface stacking order, see also activate() */ |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 784 | switch (priv->type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 785 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 786 | /* background always visible, at the bottom */ |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 787 | wl_list_insert(compositor->surface_list.prev, &surface->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 788 | break; |
| 789 | case SHELL_SURFACE_PANEL: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 790 | /* panel always on top, hidden while locked */ |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 791 | wl_list_insert(list, &surface->link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 792 | break; |
| 793 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 794 | /* lock surface always visible, on top */ |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 795 | wl_list_insert(&compositor->surface_list, &surface->link); |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 796 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 797 | wlsc_compositor_repick(compositor); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 798 | wlsc_compositor_wake(compositor); |
| 799 | break; |
| 800 | default: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 801 | /* everything else just below the panel */ |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 802 | if (!wl_list_empty(&shell->panels)) { |
| 803 | struct shell_surface *panel = |
| 804 | container_of(shell->panels.prev, |
| 805 | struct shell_surface, link); |
| 806 | wl_list_insert(&panel->surface->link, &surface->link); |
| 807 | } else { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 808 | wl_list_insert(list, &surface->link); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 809 | } |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 810 | } |
| 811 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 812 | if (priv->type == SHELL_SURFACE_TOPLEVEL) { |
Kristian Høgsberg | 4677013 | 2011-11-09 12:38:53 -0500 | [diff] [blame] | 813 | surface->x = 10 + random() % 400; |
| 814 | surface->y = 10 + random() % 400; |
| 815 | } |
| 816 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 817 | surface->width = width; |
| 818 | surface->height = height; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 819 | if (!shell->locked || priv->type == SHELL_SURFACE_LOCK) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 820 | wlsc_surface_configure(surface, |
| 821 | surface->x, surface->y, width, height); |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static void |
| 825 | configure(struct wlsc_shell *shell, struct wlsc_surface *surface, |
| 826 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 827 | { |
| 828 | struct wlsc_mode *current; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 829 | struct shell_surface *priv; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 830 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 831 | priv = get_shell_surface(surface); |
| 832 | switch (priv->type) { |
| 833 | case SHELL_SURFACE_FULLSCREEN: |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 834 | current = surface->fullscreen_output->current; |
| 835 | x = (current->width - surface->width) / 2; |
| 836 | y = (current->height - surface->height) / 2; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 837 | break; |
| 838 | default: |
| 839 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 840 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 841 | |
| 842 | wlsc_surface_configure(surface, x, y, width, height); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 843 | } |
| 844 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 845 | static void |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 846 | desktop_shell_sigchld(struct wlsc_process *process, int status) |
| 847 | { |
| 848 | struct wl_shell *shell = |
| 849 | container_of(process, struct wl_shell, child.process); |
| 850 | |
| 851 | shell->child.process.pid = 0; |
| 852 | shell->child.client = NULL; /* already destroyed by wayland */ |
| 853 | } |
| 854 | |
| 855 | static int |
| 856 | launch_desktop_shell_process(struct wl_shell *shell) |
| 857 | { |
Kristian Høgsberg | c4693c4 | 2011-11-14 14:57:17 -0500 | [diff] [blame] | 858 | const char *shell_exe = LIBEXECDIR "/wayland-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 859 | struct wlsc_compositor *compositor = shell->compositor; |
| 860 | char s[32]; |
| 861 | int sv[2], flags; |
| 862 | |
| 863 | if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) { |
| 864 | fprintf(stderr, "socketpair failed\n"); |
| 865 | return -1; |
| 866 | } |
| 867 | |
| 868 | shell->child.process.pid = fork(); |
| 869 | shell->child.process.cleanup = desktop_shell_sigchld; |
| 870 | |
| 871 | switch (shell->child.process.pid) { |
| 872 | case 0: |
| 873 | /* SOCK_CLOEXEC closes both ends, so we need to unset |
| 874 | * the flag on the client fd. */ |
| 875 | flags = fcntl(sv[1], F_GETFD); |
| 876 | if (flags != -1) |
| 877 | fcntl(sv[1], F_SETFD, flags & ~FD_CLOEXEC); |
| 878 | |
| 879 | snprintf(s, sizeof s, "%d", sv[1]); |
| 880 | setenv("WAYLAND_SOCKET", s, 1); |
| 881 | if (execl(shell_exe, shell_exe, NULL) < 0) |
| 882 | fprintf(stderr, "%s: running '%s' failed: %m\n", |
| 883 | __func__, shell_exe); |
| 884 | exit(-1); |
| 885 | |
| 886 | default: |
| 887 | close(sv[1]); |
| 888 | shell->child.client = |
| 889 | wl_client_create(compositor->wl_display, sv[0]); |
| 890 | wlsc_watch_process(&shell->child.process); |
| 891 | break; |
| 892 | |
| 893 | case -1: |
| 894 | fprintf(stderr, "%s: fork failed: %m\n", __func__); |
| 895 | return -1; |
| 896 | } |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 901 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 902 | { |
| 903 | struct wl_shell *shell = data; |
| 904 | |
| 905 | wl_client_add_object(client, &wl_shell_interface, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame^] | 906 | &shell_implementation, id, shell); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 907 | } |
| 908 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 909 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 910 | unbind_desktop_shell(struct wl_resource *resource) |
| 911 | { |
| 912 | struct wl_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 913 | |
| 914 | if (shell->locked) |
| 915 | resume_desktop(shell); |
| 916 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 917 | shell->child.desktop_shell = NULL; |
| 918 | shell->prepare_event_sent = false; |
| 919 | free(resource); |
| 920 | } |
| 921 | |
| 922 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 923 | bind_desktop_shell(struct wl_client *client, |
| 924 | void *data, uint32_t version, uint32_t id) |
| 925 | { |
| 926 | struct wl_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 927 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 928 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 929 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 930 | &desktop_shell_implementation, |
| 931 | id, shell); |
| 932 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 933 | if (client == shell->child.client) { |
| 934 | resource->destroy = unbind_desktop_shell; |
| 935 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 936 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 937 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 938 | |
| 939 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 940 | "permission to bind desktop_shell denied"); |
| 941 | wl_resource_destroy(resource, 0); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 942 | } |
| 943 | |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 944 | int |
| 945 | shell_init(struct wlsc_compositor *ec); |
| 946 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 947 | WL_EXPORT int |
| 948 | shell_init(struct wlsc_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 949 | { |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 950 | struct wl_shell *shell; |
| 951 | |
| 952 | shell = malloc(sizeof *shell); |
| 953 | if (shell == NULL) |
| 954 | return -1; |
| 955 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 956 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 957 | shell->compositor = ec; |
| 958 | shell->shell.activate = activate; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 959 | shell->shell.lock = lock; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 960 | shell->shell.unlock = unlock; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 961 | shell->shell.map = map; |
| 962 | shell->shell.configure = configure; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 963 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 964 | wl_list_init(&shell->hidden_surface_list); |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 965 | wl_list_init(&shell->backgrounds); |
| 966 | wl_list_init(&shell->panels); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 967 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 968 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 969 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 970 | return -1; |
| 971 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 972 | if (wl_display_add_global(ec->wl_display, |
| 973 | &desktop_shell_interface, |
| 974 | shell, bind_desktop_shell) == NULL) |
| 975 | return -1; |
| 976 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 977 | if (launch_desktop_shell_process(shell) != 0) |
| 978 | return -1; |
| 979 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 980 | wlsc_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 981 | move_binding, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 982 | wlsc_compositor_add_binding(ec, 0, BTN_MIDDLE, MODIFIER_SUPER, |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 983 | resize_binding, shell); |
| 984 | |
| 985 | ec->shell = &shell->shell; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 986 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 987 | return 0; |
| 988 | } |