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