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