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