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