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