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