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