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