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