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