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