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