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