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