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