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 | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 33 | #include <sys/types.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 34 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 35 | #include <wayland-server.h> |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 36 | #include "compositor.h" |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 37 | #include "desktop-shell-server-protocol.h" |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 38 | #include "../shared/config-parser.h" |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 39 | #include "log.h" |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 40 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 41 | #define DEFAULT_NUM_WORKSPACES 1 |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 42 | #define DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH 200 |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 43 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 44 | enum animation_type { |
| 45 | ANIMATION_NONE, |
| 46 | |
| 47 | ANIMATION_ZOOM, |
| 48 | ANIMATION_FADE |
| 49 | }; |
| 50 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 51 | struct workspace { |
| 52 | struct weston_layer layer; |
| 53 | }; |
| 54 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 55 | struct desktop_shell { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 56 | struct weston_compositor *compositor; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 57 | |
| 58 | struct wl_listener lock_listener; |
| 59 | struct wl_listener unlock_listener; |
| 60 | struct wl_listener destroy_listener; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 61 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 62 | struct weston_layer fullscreen_layer; |
| 63 | struct weston_layer panel_layer; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 64 | struct weston_layer background_layer; |
| 65 | struct weston_layer lock_layer; |
| 66 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 67 | struct wl_listener pointer_focus_listener; |
| 68 | struct weston_surface *busy_surface; |
| 69 | |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 70 | struct { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 71 | struct weston_process process; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 72 | struct wl_client *client; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 73 | struct wl_resource *desktop_shell; |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 74 | |
| 75 | unsigned deathcount; |
| 76 | uint32_t deathstamp; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 77 | } child; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 78 | |
| 79 | bool locked; |
| 80 | bool prepare_event_sent; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 81 | |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 82 | struct shell_surface *lock_surface; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 83 | struct wl_listener lock_surface_listener; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 84 | |
| 85 | struct wl_list backgrounds; |
| 86 | struct wl_list panels; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 87 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 88 | struct { |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 89 | struct wl_array array; |
| 90 | unsigned int current; |
| 91 | unsigned int num; |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 92 | |
| 93 | struct weston_animation animation; |
| 94 | int anim_dir; |
| 95 | uint32_t anim_timestamp; |
| 96 | double anim_current; |
| 97 | struct workspace *anim_from; |
| 98 | struct workspace *anim_to; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 99 | } workspaces; |
| 100 | |
| 101 | struct { |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 102 | char *path; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 103 | int duration; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 104 | struct wl_resource *binding; |
| 105 | struct wl_list surfaces; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 106 | struct weston_process process; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 107 | } screensaver; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 108 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 109 | uint32_t binding_modifier; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 110 | enum animation_type win_animation_type; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 111 | struct weston_surface *debug_repaint_surface; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 112 | }; |
| 113 | |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 114 | enum shell_surface_type { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 115 | SHELL_SURFACE_NONE, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 116 | |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 117 | SHELL_SURFACE_PANEL, |
| 118 | SHELL_SURFACE_BACKGROUND, |
| 119 | SHELL_SURFACE_LOCK, |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 120 | SHELL_SURFACE_SCREENSAVER, |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 121 | |
| 122 | SHELL_SURFACE_TOPLEVEL, |
| 123 | SHELL_SURFACE_TRANSIENT, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 124 | SHELL_SURFACE_FULLSCREEN, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 125 | SHELL_SURFACE_MAXIMIZED, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 126 | SHELL_SURFACE_POPUP |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 127 | }; |
| 128 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 129 | struct ping_timer { |
| 130 | struct wl_event_source *source; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 131 | uint32_t serial; |
| 132 | }; |
| 133 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 134 | struct shell_surface { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 135 | struct wl_resource resource; |
| 136 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 137 | struct weston_surface *surface; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 138 | struct wl_listener surface_destroy_listener; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 139 | struct shell_surface *parent; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 140 | struct desktop_shell *shell; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 141 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 142 | enum shell_surface_type type, next_type; |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 143 | char *title, *class; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 144 | int32_t saved_x, saved_y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 145 | bool saved_position_valid; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 146 | bool saved_rotation_valid; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 147 | int unresponsive; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 148 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 149 | struct { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 150 | struct weston_transform transform; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 151 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 152 | } rotation; |
| 153 | |
| 154 | struct { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 155 | struct wl_pointer_grab grab; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 156 | int32_t x, y; |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 157 | struct weston_transform parent_transform; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 158 | int32_t initial_up; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 159 | struct wl_seat *seat; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 160 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 161 | } popup; |
| 162 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 163 | struct { |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 164 | int32_t x, y; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 165 | uint32_t flags; |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 166 | } transient; |
| 167 | |
| 168 | struct { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 169 | enum wl_shell_surface_fullscreen_method type; |
| 170 | struct weston_transform transform; /* matrix from x, y */ |
| 171 | uint32_t framerate; |
| 172 | struct weston_surface *black_surface; |
| 173 | } fullscreen; |
| 174 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 175 | struct ping_timer *ping_timer; |
| 176 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 177 | struct weston_transform workspace_transform; |
| 178 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 179 | struct weston_output *fullscreen_output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 180 | struct weston_output *output; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 181 | struct wl_list link; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 182 | |
| 183 | const struct weston_shell_client *client; |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 184 | }; |
| 185 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 186 | struct shell_grab { |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 187 | struct wl_pointer_grab grab; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 188 | struct shell_surface *shsurf; |
| 189 | struct wl_listener shsurf_destroy_listener; |
| 190 | }; |
| 191 | |
| 192 | struct weston_move_grab { |
| 193 | struct shell_grab base; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 194 | wl_fixed_t dx, dy; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 195 | }; |
| 196 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 197 | struct rotate_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 198 | struct shell_grab base; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 199 | struct weston_matrix rotation; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 200 | struct { |
Kristian Høgsberg | b2af93e | 2012-06-07 20:10:23 -0400 | [diff] [blame] | 201 | GLfloat x; |
| 202 | GLfloat y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 203 | } center; |
| 204 | }; |
| 205 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 206 | static struct shell_surface * |
| 207 | get_shell_surface(struct weston_surface *surface); |
| 208 | |
| 209 | static struct desktop_shell * |
| 210 | shell_surface_get_shell(struct shell_surface *shsurf); |
| 211 | |
| 212 | static bool |
| 213 | shell_surface_is_top_fullscreen(struct shell_surface *shsurf) |
| 214 | { |
| 215 | struct desktop_shell *shell; |
| 216 | struct weston_surface *top_fs_es; |
| 217 | |
| 218 | shell = shell_surface_get_shell(shsurf); |
| 219 | |
| 220 | if (wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 221 | return false; |
| 222 | |
| 223 | top_fs_es = container_of(shell->fullscreen_layer.surface_list.next, |
| 224 | struct weston_surface, |
| 225 | layer_link); |
| 226 | return (shsurf == get_shell_surface(top_fs_es)); |
| 227 | } |
| 228 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 229 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 230 | destroy_shell_grab_shsurf(struct wl_listener *listener, void *data) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 231 | { |
| 232 | struct shell_grab *grab; |
| 233 | |
| 234 | grab = container_of(listener, struct shell_grab, |
| 235 | shsurf_destroy_listener); |
| 236 | |
| 237 | grab->shsurf = NULL; |
| 238 | } |
| 239 | |
| 240 | static void |
| 241 | shell_grab_init(struct shell_grab *grab, |
| 242 | const struct wl_pointer_grab_interface *interface, |
| 243 | struct shell_surface *shsurf) |
| 244 | { |
| 245 | grab->grab.interface = interface; |
| 246 | grab->shsurf = shsurf; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 247 | grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf; |
| 248 | wl_signal_add(&shsurf->resource.destroy_signal, |
| 249 | &grab->shsurf_destroy_listener); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 250 | |
| 251 | } |
| 252 | |
| 253 | static void |
| 254 | shell_grab_finish(struct shell_grab *grab) |
| 255 | { |
Kristian Høgsberg | 47b5dca | 2012-06-07 18:08:04 -0400 | [diff] [blame] | 256 | if (grab->shsurf) |
| 257 | wl_list_remove(&grab->shsurf_destroy_listener.link); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static void |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 261 | center_on_output(struct weston_surface *surface, |
| 262 | struct weston_output *output); |
| 263 | |
Daniel Stone | 496ca17 | 2012-05-30 16:31:42 +0100 | [diff] [blame] | 264 | static enum weston_keyboard_modifier |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 265 | get_modifier(char *modifier) |
| 266 | { |
| 267 | if (!modifier) |
| 268 | return MODIFIER_SUPER; |
| 269 | |
| 270 | if (!strcmp("ctrl", modifier)) |
| 271 | return MODIFIER_CTRL; |
| 272 | else if (!strcmp("alt", modifier)) |
| 273 | return MODIFIER_ALT; |
| 274 | else if (!strcmp("super", modifier)) |
| 275 | return MODIFIER_SUPER; |
| 276 | else |
| 277 | return MODIFIER_SUPER; |
| 278 | } |
| 279 | |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 280 | static enum animation_type |
| 281 | get_animation_type(char *animation) |
| 282 | { |
| 283 | if (!animation) |
| 284 | return ANIMATION_NONE; |
| 285 | |
| 286 | if (!strcmp("zoom", animation)) |
| 287 | return ANIMATION_ZOOM; |
| 288 | else if (!strcmp("fade", animation)) |
| 289 | return ANIMATION_FADE; |
| 290 | else |
| 291 | return ANIMATION_NONE; |
| 292 | } |
| 293 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 294 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 295 | shell_configuration(struct desktop_shell *shell) |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 296 | { |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 297 | char *config_file; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 298 | char *path = NULL; |
| 299 | int duration = 60; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 300 | unsigned int num_workspaces = DEFAULT_NUM_WORKSPACES; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 301 | char *modifier = NULL; |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 302 | char *win_animation = NULL; |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 303 | |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 304 | struct config_key shell_keys[] = { |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 305 | { "binding-modifier", CONFIG_KEY_STRING, &modifier }, |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 306 | { "animation", CONFIG_KEY_STRING, &win_animation}, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 307 | { "num-workspaces", |
| 308 | CONFIG_KEY_UNSIGNED_INTEGER, &num_workspaces }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 309 | }; |
| 310 | |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 311 | struct config_key saver_keys[] = { |
| 312 | { "path", CONFIG_KEY_STRING, &path }, |
| 313 | { "duration", CONFIG_KEY_INTEGER, &duration }, |
| 314 | }; |
| 315 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 316 | struct config_section cs[] = { |
Kristian Høgsberg | a4e8b33 | 2012-04-20 16:48:21 -0400 | [diff] [blame] | 317 | { "shell", shell_keys, ARRAY_LENGTH(shell_keys), NULL }, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 318 | { "screensaver", saver_keys, ARRAY_LENGTH(saver_keys), NULL }, |
| 319 | }; |
| 320 | |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 321 | config_file = config_file_path("weston.ini"); |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 322 | parse_config_file(config_file, cs, ARRAY_LENGTH(cs), shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 323 | free(config_file); |
| 324 | |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 325 | shell->screensaver.path = path; |
| 326 | shell->screensaver.duration = duration; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 327 | shell->binding_modifier = get_modifier(modifier); |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 328 | shell->win_animation_type = get_animation_type(win_animation); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 329 | shell->workspaces.num = num_workspaces > 0 ? num_workspaces : 1; |
| 330 | } |
| 331 | |
| 332 | static void |
| 333 | workspace_destroy(struct workspace *ws) |
| 334 | { |
| 335 | free(ws); |
| 336 | } |
| 337 | |
| 338 | static struct workspace * |
| 339 | workspace_create(void) |
| 340 | { |
| 341 | struct workspace *ws = malloc(sizeof *ws); |
| 342 | if (ws == NULL) |
| 343 | return NULL; |
| 344 | |
| 345 | weston_layer_init(&ws->layer, NULL); |
| 346 | |
| 347 | return ws; |
| 348 | } |
| 349 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 350 | static int |
| 351 | workspace_is_empty(struct workspace *ws) |
| 352 | { |
| 353 | return wl_list_empty(&ws->layer.surface_list); |
| 354 | } |
| 355 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 356 | static struct workspace * |
| 357 | get_workspace(struct desktop_shell *shell, unsigned int index) |
| 358 | { |
| 359 | struct workspace **pws = shell->workspaces.array.data; |
| 360 | pws += index; |
| 361 | return *pws; |
| 362 | } |
| 363 | |
| 364 | static struct workspace * |
| 365 | get_current_workspace(struct desktop_shell *shell) |
| 366 | { |
| 367 | return get_workspace(shell, shell->workspaces.current); |
| 368 | } |
| 369 | |
| 370 | static void |
| 371 | activate_workspace(struct desktop_shell *shell, unsigned int index) |
| 372 | { |
| 373 | struct workspace *ws; |
| 374 | |
| 375 | ws = get_workspace(shell, index); |
| 376 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
| 377 | |
| 378 | shell->workspaces.current = index; |
| 379 | } |
| 380 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 381 | static unsigned int |
| 382 | get_output_height(struct weston_output *output) |
| 383 | { |
| 384 | return abs(output->region.extents.y1 - output->region.extents.y2); |
| 385 | } |
| 386 | |
| 387 | static void |
| 388 | surface_translate(struct weston_surface *surface, double d) |
| 389 | { |
| 390 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 391 | struct weston_transform *transform; |
| 392 | |
| 393 | transform = &shsurf->workspace_transform; |
| 394 | if (wl_list_empty(&transform->link)) |
| 395 | wl_list_insert(surface->geometry.transformation_list.prev, |
| 396 | &shsurf->workspace_transform.link); |
| 397 | |
| 398 | weston_matrix_init(&shsurf->workspace_transform.matrix); |
| 399 | weston_matrix_translate(&shsurf->workspace_transform.matrix, |
| 400 | 0.0, d, 0.0); |
| 401 | surface->geometry.dirty = 1; |
| 402 | } |
| 403 | |
| 404 | static void |
| 405 | workspace_translate_out(struct workspace *ws, double fraction) |
| 406 | { |
| 407 | struct weston_surface *surface; |
| 408 | unsigned int height; |
| 409 | double d; |
| 410 | |
| 411 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 412 | height = get_output_height(surface->output); |
| 413 | d = height * fraction; |
| 414 | |
| 415 | surface_translate(surface, d); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | static void |
| 420 | workspace_translate_in(struct workspace *ws, double fraction) |
| 421 | { |
| 422 | struct weston_surface *surface; |
| 423 | unsigned int height; |
| 424 | double d; |
| 425 | |
| 426 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 427 | height = get_output_height(surface->output); |
| 428 | |
| 429 | if (fraction > 0) |
| 430 | d = -(height - height * fraction); |
| 431 | else |
| 432 | d = height + height * fraction; |
| 433 | |
| 434 | surface_translate(surface, d); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | static void |
| 439 | workspace_damage_all_surfaces(struct workspace *ws) |
| 440 | { |
| 441 | struct weston_surface *surface; |
| 442 | |
| 443 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) |
| 444 | weston_surface_damage(surface); |
| 445 | } |
| 446 | |
| 447 | static void |
| 448 | reverse_workspace_change_animation(struct desktop_shell *shell, |
| 449 | unsigned int index, |
| 450 | struct workspace *from, |
| 451 | struct workspace *to) |
| 452 | { |
| 453 | shell->workspaces.current = index; |
| 454 | |
| 455 | shell->workspaces.anim_to = to; |
| 456 | shell->workspaces.anim_from = from; |
| 457 | shell->workspaces.anim_dir = -1 * shell->workspaces.anim_dir; |
| 458 | shell->workspaces.anim_timestamp = 0; |
| 459 | |
| 460 | workspace_damage_all_surfaces(from); |
| 461 | workspace_damage_all_surfaces(to); |
| 462 | } |
| 463 | |
| 464 | static void |
| 465 | workspace_deactivate_transforms(struct workspace *ws) |
| 466 | { |
| 467 | struct weston_surface *surface; |
| 468 | struct shell_surface *shsurf; |
| 469 | |
| 470 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
| 471 | shsurf = get_shell_surface(surface); |
| 472 | wl_list_remove(&shsurf->workspace_transform.link); |
| 473 | wl_list_init(&shsurf->workspace_transform.link); |
| 474 | shsurf->surface->geometry.dirty = 1; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | static void |
| 479 | finish_workspace_change_animation(struct desktop_shell *shell, |
| 480 | struct workspace *from, |
| 481 | struct workspace *to) |
| 482 | { |
| 483 | workspace_damage_all_surfaces(from); |
| 484 | workspace_damage_all_surfaces(to); |
| 485 | |
| 486 | wl_list_remove(&shell->workspaces.animation.link); |
| 487 | workspace_deactivate_transforms(from); |
| 488 | workspace_deactivate_transforms(to); |
| 489 | shell->workspaces.anim_to = NULL; |
| 490 | |
| 491 | wl_list_remove(&shell->workspaces.anim_from->layer.link); |
| 492 | } |
| 493 | |
| 494 | static void |
| 495 | animate_workspace_change_frame(struct weston_animation *animation, |
| 496 | struct weston_output *output, uint32_t msecs) |
| 497 | { |
| 498 | struct desktop_shell *shell = |
| 499 | container_of(animation, struct desktop_shell, |
| 500 | workspaces.animation); |
| 501 | struct workspace *from = shell->workspaces.anim_from; |
| 502 | struct workspace *to = shell->workspaces.anim_to; |
| 503 | uint32_t t; |
| 504 | double x, y; |
| 505 | |
| 506 | if (workspace_is_empty(from) && workspace_is_empty(to)) { |
| 507 | finish_workspace_change_animation(shell, from, to); |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | if (shell->workspaces.anim_timestamp == 0) { |
| 512 | if (shell->workspaces.anim_current == 0.0) |
| 513 | shell->workspaces.anim_timestamp = msecs; |
| 514 | else |
| 515 | shell->workspaces.anim_timestamp = |
| 516 | msecs - |
| 517 | /* Invers of movement function 'y' below. */ |
| 518 | (asin(1.0 - shell->workspaces.anim_current) * |
| 519 | DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH * |
| 520 | M_2_PI); |
| 521 | } |
| 522 | |
| 523 | t = msecs - shell->workspaces.anim_timestamp; |
| 524 | |
| 525 | /* |
| 526 | * x = [0, π/2] |
| 527 | * y(x) = sin(x) |
| 528 | */ |
| 529 | x = t * (1.0/DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) * M_PI_2; |
| 530 | y = sin(x); |
| 531 | |
| 532 | if (t < DEFAULT_WORKSPACE_CHANGE_ANIMATION_LENGTH) { |
| 533 | workspace_damage_all_surfaces(from); |
| 534 | workspace_damage_all_surfaces(to); |
| 535 | |
| 536 | workspace_translate_out(from, shell->workspaces.anim_dir * y); |
| 537 | workspace_translate_in(to, shell->workspaces.anim_dir * y); |
| 538 | shell->workspaces.anim_current = y; |
| 539 | |
| 540 | workspace_damage_all_surfaces(from); |
| 541 | workspace_damage_all_surfaces(to); |
| 542 | } |
| 543 | else { |
| 544 | finish_workspace_change_animation(shell, from, to); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | static void |
| 549 | animate_workspace_change(struct desktop_shell *shell, |
| 550 | unsigned int index, |
| 551 | struct workspace *from, |
| 552 | struct workspace *to) |
| 553 | { |
| 554 | struct weston_output *output; |
| 555 | |
| 556 | int dir; |
| 557 | |
| 558 | if (index > shell->workspaces.current) |
| 559 | dir = -1; |
| 560 | else |
| 561 | dir = 1; |
| 562 | |
| 563 | shell->workspaces.current = index; |
| 564 | |
| 565 | shell->workspaces.anim_dir = dir; |
| 566 | shell->workspaces.anim_from = from; |
| 567 | shell->workspaces.anim_to = to; |
| 568 | shell->workspaces.anim_current = 0.0; |
| 569 | shell->workspaces.anim_timestamp = 0; |
| 570 | |
| 571 | output = container_of(shell->compositor->output_list.next, |
| 572 | struct weston_output, link); |
| 573 | wl_list_insert(&output->animation_list, |
| 574 | &shell->workspaces.animation.link); |
| 575 | |
| 576 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 577 | |
| 578 | workspace_translate_in(to, 0); |
| 579 | |
| 580 | workspace_damage_all_surfaces(from); |
| 581 | workspace_damage_all_surfaces(to); |
| 582 | } |
| 583 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 584 | static void |
| 585 | change_workspace(struct desktop_shell *shell, unsigned int index) |
| 586 | { |
| 587 | struct workspace *from; |
| 588 | struct workspace *to; |
| 589 | struct weston_seat *seat; |
| 590 | |
| 591 | if (index == shell->workspaces.current) |
| 592 | return; |
| 593 | |
| 594 | /* Don't change workspace when there is any fullscreen surfaces. */ |
| 595 | if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) |
| 596 | return; |
| 597 | |
| 598 | /* Clear keyboard focus so that no hidden surfaces will keep it. */ |
| 599 | wl_list_for_each(seat, &shell->compositor->seat_list, link) |
| 600 | if (seat->seat.keyboard) |
| 601 | wl_keyboard_set_focus(seat->seat.keyboard, NULL); |
| 602 | |
| 603 | from = get_current_workspace(shell); |
| 604 | to = get_workspace(shell, index); |
| 605 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 606 | if (shell->workspaces.anim_from == to && |
| 607 | shell->workspaces.anim_to == from) { |
| 608 | reverse_workspace_change_animation(shell, index, from, to); |
| 609 | return; |
| 610 | } |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 611 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 612 | if (shell->workspaces.anim_to != NULL) |
| 613 | finish_workspace_change_animation(shell, |
| 614 | shell->workspaces.anim_from, |
| 615 | shell->workspaces.anim_to); |
| 616 | |
| 617 | if (workspace_is_empty(to) && workspace_is_empty(from)) { |
| 618 | shell->workspaces.current = index; |
| 619 | wl_list_insert(&from->layer.link, &to->layer.link); |
| 620 | wl_list_remove(&from->layer.link); |
| 621 | } |
| 622 | else |
| 623 | animate_workspace_change(shell, index, from, to); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 624 | } |
| 625 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 626 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 627 | noop_grab_focus(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 628 | struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 629 | { |
| 630 | grab->focus = NULL; |
| 631 | } |
| 632 | |
| 633 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 634 | move_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 635 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 636 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 637 | struct weston_move_grab *move = (struct weston_move_grab *) grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 638 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 639 | struct shell_surface *shsurf = move->base.shsurf; |
| 640 | struct weston_surface *es; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 641 | int dx = wl_fixed_to_int(pointer->x + move->dx); |
| 642 | int dy = wl_fixed_to_int(pointer->y + move->dy); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 643 | |
| 644 | if (!shsurf) |
| 645 | return; |
| 646 | |
| 647 | es = shsurf->surface; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 648 | |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 649 | weston_surface_configure(es, dx, dy, |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 650 | es->geometry.width, es->geometry.height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 654 | move_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 655 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 656 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 657 | struct shell_grab *shell_grab = container_of(grab, struct shell_grab, |
| 658 | grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 659 | struct wl_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 660 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 661 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 662 | if (pointer->button_count == 0 && |
| 663 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 664 | shell_grab_finish(shell_grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 665 | wl_pointer_end_grab(pointer); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 666 | free(grab); |
| 667 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 668 | } |
| 669 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 670 | static const struct wl_pointer_grab_interface move_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 671 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 672 | move_grab_motion, |
| 673 | move_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 674 | }; |
| 675 | |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 676 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 677 | busy_cursor_grab_focus(struct wl_pointer_grab *base, |
| 678 | struct wl_surface *surface, int32_t x, int32_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 679 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 680 | struct shell_grab *grab = (struct shell_grab *) base; |
| 681 | struct wl_pointer *pointer = base->pointer; |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 682 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 683 | if (grab->grab.focus != surface) { |
| 684 | shell_grab_finish(grab); |
| 685 | wl_pointer_end_grab(pointer); |
| 686 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
| 690 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 691 | busy_cursor_grab_motion(struct wl_pointer_grab *grab, |
| 692 | uint32_t time, int32_t x, int32_t y) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 693 | { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 694 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 695 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 696 | static void |
| 697 | busy_cursor_grab_button(struct wl_pointer_grab *grab, |
| 698 | uint32_t time, uint32_t button, uint32_t state) |
| 699 | { |
| 700 | } |
| 701 | |
| 702 | static const struct wl_pointer_grab_interface busy_cursor_grab_interface = { |
| 703 | busy_cursor_grab_focus, |
| 704 | busy_cursor_grab_motion, |
| 705 | busy_cursor_grab_button, |
| 706 | }; |
| 707 | |
| 708 | static void |
| 709 | set_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer) |
| 710 | { |
| 711 | struct shell_grab *grab; |
| 712 | struct desktop_shell *shell = shsurf->shell; |
| 713 | struct weston_seat *seat = (struct weston_seat *) pointer->seat; |
| 714 | struct weston_surface *sprite; |
| 715 | |
| 716 | grab = malloc(sizeof *grab); |
| 717 | if (!grab) |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 718 | return; |
| 719 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 720 | shell_grab_init(grab, &busy_cursor_grab_interface, shsurf); |
| 721 | grab->grab.focus = &shsurf->surface->surface; |
| 722 | wl_pointer_start_grab(pointer, &grab->grab); |
| 723 | wl_pointer_set_focus(pointer, &shell->busy_surface->surface, 0, 0); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 724 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 725 | sprite = (struct weston_surface *) seat->sprite; |
| 726 | shell->busy_surface->output = sprite->output; |
| 727 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 728 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 729 | static void |
| 730 | end_busy_cursor(struct shell_surface *shsurf, struct wl_pointer *pointer) |
| 731 | { |
| 732 | struct shell_grab *grab = (struct shell_grab *) pointer->grab; |
| 733 | |
| 734 | if (grab->grab.interface == &busy_cursor_grab_interface) { |
| 735 | shell_grab_finish(grab); |
| 736 | wl_pointer_end_grab(pointer); |
| 737 | free(grab); |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 738 | } |
Scott Moreau | c3e54eb | 2012-04-17 19:06:20 -0600 | [diff] [blame] | 739 | } |
| 740 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 741 | static void |
| 742 | ping_timer_destroy(struct shell_surface *shsurf) |
| 743 | { |
| 744 | if (!shsurf || !shsurf->ping_timer) |
| 745 | return; |
| 746 | |
| 747 | if (shsurf->ping_timer->source) |
| 748 | wl_event_source_remove(shsurf->ping_timer->source); |
| 749 | |
| 750 | free(shsurf->ping_timer); |
| 751 | shsurf->ping_timer = NULL; |
| 752 | } |
| 753 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 754 | static int |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 755 | ping_timeout_handler(void *data) |
| 756 | { |
| 757 | struct shell_surface *shsurf = data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 758 | struct weston_seat *seat; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 759 | |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 760 | /* Client is not responding */ |
| 761 | shsurf->unresponsive = 1; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 762 | |
| 763 | wl_list_for_each(seat, &shsurf->surface->compositor->seat_list, link) |
| 764 | if (seat->seat.pointer->focus == &shsurf->surface->surface) |
| 765 | set_busy_cursor(shsurf, seat->seat.pointer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 766 | |
| 767 | return 1; |
| 768 | } |
| 769 | |
| 770 | static void |
| 771 | ping_handler(struct weston_surface *surface, uint32_t serial) |
| 772 | { |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 773 | struct shell_surface *shsurf = get_shell_surface(surface); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 774 | struct wl_event_loop *loop; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 775 | int ping_timeout = 200; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 776 | |
| 777 | if (!shsurf) |
| 778 | return; |
Kristian Høgsberg | ca535c1 | 2012-04-21 23:20:07 -0400 | [diff] [blame] | 779 | if (!shsurf->resource.client) |
| 780 | return; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 781 | |
| 782 | if (!shsurf->ping_timer) { |
Ander Conselvan de Oliveira | fb98089 | 2012-04-27 13:55:55 +0300 | [diff] [blame] | 783 | shsurf->ping_timer = malloc(sizeof *shsurf->ping_timer); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 784 | if (!shsurf->ping_timer) |
| 785 | return; |
| 786 | |
| 787 | shsurf->ping_timer->serial = serial; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 788 | loop = wl_display_get_event_loop(surface->compositor->wl_display); |
| 789 | shsurf->ping_timer->source = |
| 790 | wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf); |
| 791 | wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout); |
| 792 | |
| 793 | wl_shell_surface_send_ping(&shsurf->resource, serial); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | static void |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 798 | handle_pointer_focus(struct wl_listener *listener, void *data) |
| 799 | { |
| 800 | struct wl_pointer *pointer = data; |
| 801 | struct weston_surface *surface = |
| 802 | (struct weston_surface *) pointer->focus; |
| 803 | struct weston_compositor *compositor; |
| 804 | struct shell_surface *shsurf; |
| 805 | uint32_t serial; |
| 806 | |
| 807 | if (!surface) |
| 808 | return; |
| 809 | |
| 810 | compositor = surface->compositor; |
| 811 | shsurf = get_shell_surface(surface); |
| 812 | |
Pekka Paalanen | 4e1f2ff | 2012-06-06 16:59:45 +0300 | [diff] [blame] | 813 | if (shsurf && shsurf->unresponsive) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 814 | set_busy_cursor(shsurf, pointer); |
| 815 | } else { |
| 816 | serial = wl_display_next_serial(compositor->wl_display); |
| 817 | ping_handler(surface, serial); |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | static void |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 822 | shell_surface_pong(struct wl_client *client, struct wl_resource *resource, |
| 823 | uint32_t serial) |
| 824 | { |
| 825 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 826 | struct desktop_shell *shell = shsurf->shell; |
| 827 | struct weston_seat *seat; |
| 828 | struct weston_compositor *ec = shsurf->surface->compositor; |
| 829 | struct wl_pointer *pointer; |
| 830 | int was_unresponsive; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 831 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 832 | if (shsurf->ping_timer->serial == serial) { |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 833 | was_unresponsive = shsurf->unresponsive; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 834 | shsurf->unresponsive = 0; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 835 | if (was_unresponsive) { |
| 836 | /* Received pong from previously unresponsive client */ |
| 837 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 838 | pointer = seat->seat.pointer; |
| 839 | if (pointer->focus == |
| 840 | &shell->busy_surface->surface && |
| 841 | pointer->current == |
| 842 | &shsurf->surface->surface) |
| 843 | end_busy_cursor(shsurf, pointer); |
| 844 | } |
| 845 | } |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 846 | ping_timer_destroy(shsurf); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 850 | static void |
| 851 | shell_surface_set_title(struct wl_client *client, |
| 852 | struct wl_resource *resource, const char *title) |
| 853 | { |
| 854 | struct shell_surface *shsurf = resource->data; |
| 855 | |
| 856 | free(shsurf->title); |
| 857 | shsurf->title = strdup(title); |
| 858 | } |
| 859 | |
| 860 | static void |
| 861 | shell_surface_set_class(struct wl_client *client, |
| 862 | struct wl_resource *resource, const char *class) |
| 863 | { |
| 864 | struct shell_surface *shsurf = resource->data; |
| 865 | |
| 866 | free(shsurf->class); |
| 867 | shsurf->class = strdup(class); |
| 868 | } |
| 869 | |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 870 | static int |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 871 | surface_move(struct shell_surface *shsurf, struct weston_seat *ws) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 872 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 873 | struct weston_move_grab *move; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 874 | |
| 875 | if (!shsurf) |
| 876 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 877 | |
| 878 | move = malloc(sizeof *move); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 879 | if (!move) |
| 880 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 881 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 882 | shell_grab_init(&move->base, &move_grab_interface, shsurf); |
| 883 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 884 | move->dx = wl_fixed_from_double(shsurf->surface->geometry.x) - |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 885 | ws->seat.pointer->grab_x; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 886 | move->dy = wl_fixed_from_double(shsurf->surface->geometry.y) - |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 887 | ws->seat.pointer->grab_y; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 888 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 889 | wl_pointer_start_grab(ws->seat.pointer, &move->base.grab); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 890 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 891 | wl_pointer_set_focus(ws->seat.pointer, NULL, |
| 892 | wl_fixed_from_int(0), |
| 893 | wl_fixed_from_int(0)); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 894 | |
| 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 899 | shell_surface_move(struct wl_client *client, struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 900 | struct wl_resource *seat_resource, uint32_t serial) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 901 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 902 | struct weston_seat *ws = seat_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 903 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 904 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 905 | if (ws->seat.pointer->button_count == 0 || |
| 906 | ws->seat.pointer->grab_serial != serial || |
| 907 | ws->seat.pointer->focus != &shsurf->surface->surface) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 908 | return; |
| 909 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 910 | if (surface_move(shsurf, ws) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 911 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 912 | } |
| 913 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 914 | struct weston_resize_grab { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 915 | struct shell_grab base; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 916 | uint32_t edges; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 917 | int32_t width, height; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 918 | }; |
| 919 | |
| 920 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 921 | resize_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 922 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 923 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 924 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 925 | struct wl_pointer *pointer = grab->pointer; |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 926 | struct shell_surface *shsurf = resize->base.shsurf; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 927 | int32_t width, height; |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 928 | wl_fixed_t from_x, from_y; |
| 929 | wl_fixed_t to_x, to_y; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 930 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 931 | if (!shsurf) |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 932 | return; |
| 933 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 934 | weston_surface_from_global_fixed(shsurf->surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 935 | pointer->grab_x, pointer->grab_y, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 936 | &from_x, &from_y); |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 937 | weston_surface_from_global_fixed(shsurf->surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 938 | pointer->x, pointer->y, &to_x, &to_y); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 939 | |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 940 | width = resize->width; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 941 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_LEFT) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 942 | width += wl_fixed_to_int(from_x - to_x); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 943 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_RIGHT) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 944 | width += wl_fixed_to_int(to_x - from_x); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 945 | } |
| 946 | |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 947 | height = resize->height; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 948 | if (resize->edges & WL_SHELL_SURFACE_RESIZE_TOP) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 949 | height += wl_fixed_to_int(from_y - to_y); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 950 | } else if (resize->edges & WL_SHELL_SURFACE_RESIZE_BOTTOM) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 951 | height += wl_fixed_to_int(to_y - from_y); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 952 | } |
| 953 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 954 | shsurf->client->send_configure(shsurf->surface, |
| 955 | resize->edges, width, height); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | static void |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 959 | send_configure(struct weston_surface *surface, |
| 960 | uint32_t edges, int32_t width, int32_t height) |
| 961 | { |
| 962 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 963 | |
| 964 | wl_shell_surface_send_configure(&shsurf->resource, |
| 965 | edges, width, height); |
| 966 | } |
| 967 | |
| 968 | static const struct weston_shell_client shell_client = { |
| 969 | send_configure |
| 970 | }; |
| 971 | |
| 972 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 973 | resize_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 974 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 975 | { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 976 | struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 977 | struct wl_pointer *pointer = grab->pointer; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 978 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 979 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 980 | if (pointer->button_count == 0 && |
| 981 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 982 | shell_grab_finish(&resize->base); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 983 | wl_pointer_end_grab(pointer); |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 984 | free(grab); |
| 985 | } |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 986 | } |
| 987 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 988 | static const struct wl_pointer_grab_interface resize_grab_interface = { |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 989 | noop_grab_focus, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 990 | resize_grab_motion, |
| 991 | resize_grab_button, |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 992 | }; |
| 993 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 994 | static int |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 995 | surface_resize(struct shell_surface *shsurf, |
| 996 | struct weston_seat *ws, uint32_t edges) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 997 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 998 | struct weston_resize_grab *resize; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 999 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1000 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1001 | return 0; |
Kristian Høgsberg | 0ce2457 | 2011-01-28 15:18:33 -0500 | [diff] [blame] | 1002 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1003 | if (edges == 0 || edges > 15 || |
| 1004 | (edges & 3) == 3 || (edges & 12) == 12) |
| 1005 | return 0; |
| 1006 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1007 | resize = malloc(sizeof *resize); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1008 | if (!resize) |
| 1009 | return -1; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1010 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 1011 | shell_grab_init(&resize->base, &resize_grab_interface, shsurf); |
| 1012 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1013 | resize->edges = edges; |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1014 | resize->width = shsurf->surface->geometry.width; |
| 1015 | resize->height = shsurf->surface->geometry.height; |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1016 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1017 | wl_pointer_start_grab(ws->seat.pointer, &resize->base.grab); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1018 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1019 | wl_pointer_set_focus(ws->seat.pointer, NULL, |
| 1020 | wl_fixed_from_int(0), |
| 1021 | wl_fixed_from_int(0)); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1022 | |
| 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1027 | shell_surface_resize(struct wl_client *client, struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1028 | struct wl_resource *seat_resource, uint32_t serial, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1029 | uint32_t edges) |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1030 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1031 | struct weston_seat *ws = seat_resource->data; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1032 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1033 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1034 | if (shsurf->type == SHELL_SURFACE_FULLSCREEN) |
| 1035 | return; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 1036 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1037 | if (ws->seat.pointer->button_count == 0 || |
| 1038 | ws->seat.pointer->grab_serial != serial || |
| 1039 | ws->seat.pointer->focus != &shsurf->surface->surface) |
Kristian Høgsberg | 9ddb826 | 2012-01-04 21:30:29 -0500 | [diff] [blame] | 1040 | return; |
| 1041 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1042 | if (surface_resize(shsurf, ws, edges) < 0) |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1043 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1044 | } |
| 1045 | |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1046 | static struct weston_output * |
| 1047 | get_default_output(struct weston_compositor *compositor) |
| 1048 | { |
| 1049 | return container_of(compositor->output_list.next, |
| 1050 | struct weston_output, link); |
| 1051 | } |
| 1052 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1053 | static void |
| 1054 | shell_unset_fullscreen(struct shell_surface *shsurf) |
| 1055 | { |
| 1056 | /* undo all fullscreen things here */ |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1057 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1058 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1059 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1060 | shsurf->fullscreen_output->origin); |
| 1061 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1062 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 1063 | shsurf->fullscreen.framerate = 0; |
| 1064 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 1065 | wl_list_init(&shsurf->fullscreen.transform.link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1066 | if (shsurf->fullscreen.black_surface) |
| 1067 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1068 | shsurf->fullscreen.black_surface = NULL; |
| 1069 | shsurf->fullscreen_output = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1070 | weston_surface_set_position(shsurf->surface, |
| 1071 | shsurf->saved_x, shsurf->saved_y); |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1072 | if (shsurf->saved_rotation_valid) { |
| 1073 | wl_list_insert(&shsurf->surface->geometry.transformation_list, |
| 1074 | &shsurf->rotation.transform.link); |
| 1075 | shsurf->saved_rotation_valid = false; |
| 1076 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1077 | } |
| 1078 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1079 | static int |
| 1080 | reset_shell_surface_type(struct shell_surface *surface) |
| 1081 | { |
| 1082 | switch (surface->type) { |
| 1083 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1084 | shell_unset_fullscreen(surface); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1085 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1086 | case SHELL_SURFACE_MAXIMIZED: |
| 1087 | surface->output = get_default_output(surface->surface->compositor); |
| 1088 | weston_surface_set_position(surface->surface, |
| 1089 | surface->saved_x, |
| 1090 | surface->saved_y); |
| 1091 | break; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1092 | case SHELL_SURFACE_PANEL: |
| 1093 | case SHELL_SURFACE_BACKGROUND: |
| 1094 | wl_list_remove(&surface->link); |
| 1095 | wl_list_init(&surface->link); |
| 1096 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1097 | case SHELL_SURFACE_SCREENSAVER: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1098 | case SHELL_SURFACE_LOCK: |
| 1099 | wl_resource_post_error(&surface->resource, |
| 1100 | WL_DISPLAY_ERROR_INVALID_METHOD, |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1101 | "cannot reassign surface type"); |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1102 | return -1; |
| 1103 | case SHELL_SURFACE_NONE: |
| 1104 | case SHELL_SURFACE_TOPLEVEL: |
| 1105 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1106 | case SHELL_SURFACE_POPUP: |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1107 | break; |
| 1108 | } |
| 1109 | |
| 1110 | surface->type = SHELL_SURFACE_NONE; |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1114 | static void |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1115 | set_surface_type(struct shell_surface *shsurf) |
| 1116 | { |
| 1117 | struct weston_surface *surface = shsurf->surface; |
| 1118 | struct shell_surface *pshsurf = shsurf->parent; |
| 1119 | struct weston_surface *pes; |
| 1120 | struct shell_surface *priv; |
| 1121 | struct desktop_shell *shell = shsurf->shell; |
| 1122 | |
| 1123 | reset_shell_surface_type(shsurf); |
| 1124 | |
| 1125 | shsurf->type = shsurf->next_type; |
| 1126 | shsurf->next_type = SHELL_SURFACE_NONE; |
| 1127 | |
| 1128 | switch (shsurf->type) { |
| 1129 | case SHELL_SURFACE_TOPLEVEL: |
| 1130 | break; |
| 1131 | case SHELL_SURFACE_TRANSIENT: |
| 1132 | pes = pshsurf->surface; |
| 1133 | weston_surface_set_position(surface, |
Tiago Vignatti | 52e598c | 2012-05-07 15:23:08 +0300 | [diff] [blame] | 1134 | pes->geometry.x + shsurf->transient.x, |
| 1135 | pes->geometry.y + shsurf->transient.y); |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1136 | break; |
| 1137 | |
| 1138 | case SHELL_SURFACE_MAXIMIZED: |
| 1139 | shsurf->saved_x = surface->geometry.x; |
| 1140 | shsurf->saved_y = surface->geometry.y; |
| 1141 | shsurf->saved_position_valid = true; |
| 1142 | break; |
| 1143 | |
| 1144 | case SHELL_SURFACE_FULLSCREEN: |
| 1145 | shsurf->saved_x = surface->geometry.x; |
| 1146 | shsurf->saved_y = surface->geometry.y; |
| 1147 | shsurf->saved_position_valid = true; |
| 1148 | |
| 1149 | if (!wl_list_empty(&shsurf->rotation.transform.link)) { |
| 1150 | wl_list_remove(&shsurf->rotation.transform.link); |
| 1151 | wl_list_init(&shsurf->rotation.transform.link); |
| 1152 | shsurf->surface->geometry.dirty = 1; |
| 1153 | shsurf->saved_rotation_valid = true; |
| 1154 | } |
| 1155 | break; |
| 1156 | |
| 1157 | case SHELL_SURFACE_BACKGROUND: |
| 1158 | wl_list_for_each(priv, &shell->backgrounds, link) { |
| 1159 | if (priv->output == shsurf->output) { |
| 1160 | priv->surface->output = NULL; |
| 1161 | wl_list_remove(&priv->surface->layer_link); |
| 1162 | wl_list_remove(&priv->link); |
| 1163 | break; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | wl_list_insert(&shell->backgrounds, &shsurf->link); |
| 1168 | |
| 1169 | weston_surface_set_position(surface, shsurf->output->x, |
| 1170 | shsurf->output->y); |
| 1171 | break; |
| 1172 | |
| 1173 | case SHELL_SURFACE_PANEL: |
| 1174 | wl_list_for_each(priv, &shell->panels, link) { |
| 1175 | if (priv->output == shsurf->output) { |
| 1176 | priv->surface->output = NULL; |
| 1177 | wl_list_remove(&priv->surface->layer_link); |
| 1178 | wl_list_remove(&priv->link); |
| 1179 | break; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | wl_list_insert(&shell->panels, &shsurf->link); |
| 1184 | |
| 1185 | weston_surface_set_position(surface, shsurf->output->x, |
| 1186 | shsurf->output->y); |
| 1187 | break; |
| 1188 | |
| 1189 | default: |
| 1190 | break; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1195 | set_toplevel(struct shell_surface *shsurf) |
| 1196 | { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1197 | shsurf->next_type = SHELL_SURFACE_TOPLEVEL; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1201 | shell_surface_set_toplevel(struct wl_client *client, |
| 1202 | struct wl_resource *resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1203 | { |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1204 | struct shell_surface *surface = resource->data; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1205 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1206 | set_toplevel(surface); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | static void |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1210 | set_transient(struct shell_surface *shsurf, |
| 1211 | struct shell_surface *pshsurf, int x, int y, uint32_t flags) |
| 1212 | { |
| 1213 | /* assign to parents output */ |
| 1214 | shsurf->parent = pshsurf; |
| 1215 | shsurf->transient.x = x; |
| 1216 | shsurf->transient.y = y; |
| 1217 | shsurf->transient.flags = flags; |
| 1218 | shsurf->next_type = SHELL_SURFACE_TRANSIENT; |
| 1219 | } |
| 1220 | |
| 1221 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1222 | shell_surface_set_transient(struct wl_client *client, |
| 1223 | struct wl_resource *resource, |
| 1224 | struct wl_resource *parent_resource, |
| 1225 | int x, int y, uint32_t flags) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1226 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1227 | struct shell_surface *shsurf = resource->data; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1228 | struct shell_surface *pshsurf = parent_resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1229 | |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 1230 | set_transient(shsurf, pshsurf, x, y, flags); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1233 | static struct desktop_shell * |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1234 | shell_surface_get_shell(struct shell_surface *shsurf) |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1235 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 1236 | return shsurf->shell; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1240 | get_output_panel_height(struct desktop_shell *shell, |
| 1241 | struct weston_output *output) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1242 | { |
| 1243 | struct shell_surface *priv; |
| 1244 | int panel_height = 0; |
| 1245 | |
| 1246 | if (!output) |
| 1247 | return 0; |
| 1248 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1249 | wl_list_for_each(priv, &shell->panels, link) { |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1250 | if (priv->output == output) { |
| 1251 | panel_height = priv->surface->geometry.height; |
| 1252 | break; |
| 1253 | } |
| 1254 | } |
| 1255 | return panel_height; |
| 1256 | } |
| 1257 | |
| 1258 | static void |
| 1259 | shell_surface_set_maximized(struct wl_client *client, |
| 1260 | struct wl_resource *resource, |
| 1261 | struct wl_resource *output_resource ) |
| 1262 | { |
| 1263 | struct shell_surface *shsurf = resource->data; |
| 1264 | struct weston_surface *es = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1265 | struct desktop_shell *shell = NULL; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1266 | uint32_t edges = 0, panel_height = 0; |
| 1267 | |
| 1268 | /* get the default output, if the client set it as NULL |
| 1269 | check whether the ouput is available */ |
| 1270 | if (output_resource) |
| 1271 | shsurf->output = output_resource->data; |
| 1272 | else |
| 1273 | shsurf->output = get_default_output(es->compositor); |
| 1274 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1275 | shell = shell_surface_get_shell(shsurf); |
| 1276 | panel_height = get_output_panel_height(shell, es->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1277 | edges = WL_SHELL_SURFACE_RESIZE_TOP|WL_SHELL_SURFACE_RESIZE_LEFT; |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1278 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1279 | shsurf->client->send_configure(shsurf->surface, edges, |
| 1280 | es->output->current->width, |
| 1281 | es->output->current->height - panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1282 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1283 | shsurf->next_type = SHELL_SURFACE_MAXIMIZED; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 1284 | } |
| 1285 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1286 | static void |
| 1287 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy); |
| 1288 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1289 | static struct weston_surface * |
| 1290 | create_black_surface(struct weston_compositor *ec, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1291 | struct weston_surface *fs_surface, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1292 | GLfloat x, GLfloat y, int w, int h) |
| 1293 | { |
| 1294 | struct weston_surface *surface = NULL; |
| 1295 | |
| 1296 | surface = weston_surface_create(ec); |
| 1297 | if (surface == NULL) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1298 | weston_log("no memory\n"); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1299 | return NULL; |
| 1300 | } |
| 1301 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1302 | surface->configure = black_surface_configure; |
| 1303 | surface->private = fs_surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1304 | weston_surface_configure(surface, x, y, w, h); |
| 1305 | weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1); |
| 1306 | return surface; |
| 1307 | } |
| 1308 | |
| 1309 | /* Create black surface and append it to the associated fullscreen surface. |
| 1310 | * Handle size dismatch and positioning according to the method. */ |
| 1311 | static void |
| 1312 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 1313 | { |
| 1314 | struct weston_output *output = shsurf->fullscreen_output; |
| 1315 | struct weston_surface *surface = shsurf->surface; |
| 1316 | struct weston_matrix *matrix; |
| 1317 | float scale; |
| 1318 | |
| 1319 | center_on_output(surface, output); |
| 1320 | |
| 1321 | if (!shsurf->fullscreen.black_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1322 | shsurf->fullscreen.black_surface = |
| 1323 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1324 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1325 | output->x, output->y, |
| 1326 | output->current->width, |
| 1327 | output->current->height); |
| 1328 | |
| 1329 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
| 1330 | wl_list_insert(&surface->layer_link, |
| 1331 | &shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1332 | shsurf->fullscreen.black_surface->output = output; |
| 1333 | |
| 1334 | switch (shsurf->fullscreen.type) { |
| 1335 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
| 1336 | break; |
| 1337 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
| 1338 | matrix = &shsurf->fullscreen.transform.matrix; |
| 1339 | weston_matrix_init(matrix); |
| 1340 | scale = (float)output->current->width/(float)surface->geometry.width; |
| 1341 | weston_matrix_scale(matrix, scale, scale, 1); |
| 1342 | wl_list_remove(&shsurf->fullscreen.transform.link); |
| 1343 | wl_list_insert(surface->geometry.transformation_list.prev, |
| 1344 | &shsurf->fullscreen.transform.link); |
| 1345 | weston_surface_set_position(surface, output->x, output->y); |
| 1346 | break; |
| 1347 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1348 | if (shell_surface_is_top_fullscreen(shsurf)) { |
| 1349 | struct weston_mode mode = {0, |
| 1350 | surface->geometry.width, |
| 1351 | surface->geometry.height, |
| 1352 | shsurf->fullscreen.framerate}; |
| 1353 | |
| 1354 | if (weston_output_switch_mode(output, &mode) == 0) { |
| 1355 | weston_surface_configure(shsurf->fullscreen.black_surface, |
| 1356 | output->x, output->y, |
| 1357 | output->current->width, |
| 1358 | output->current->height); |
| 1359 | weston_surface_set_position(surface, output->x, output->y); |
| 1360 | break; |
| 1361 | } |
| 1362 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1363 | break; |
| 1364 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
| 1365 | break; |
| 1366 | default: |
| 1367 | break; |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | /* make the fullscreen and black surface at the top */ |
| 1372 | static void |
| 1373 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 1374 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1375 | struct weston_output *output = shsurf->fullscreen_output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1376 | struct weston_surface *surface = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1377 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1378 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1379 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1380 | wl_list_insert(&shell->fullscreen_layer.surface_list, |
| 1381 | &surface->layer_link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1382 | weston_surface_damage(surface); |
| 1383 | |
| 1384 | if (!shsurf->fullscreen.black_surface) |
| 1385 | shsurf->fullscreen.black_surface = |
| 1386 | create_black_surface(surface->compositor, |
| 1387 | surface, |
| 1388 | output->x, output->y, |
| 1389 | output->current->width, |
| 1390 | output->current->height); |
| 1391 | |
| 1392 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1393 | wl_list_insert(&surface->layer_link, |
| 1394 | &shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1395 | weston_surface_damage(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | static void |
| 1399 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 1400 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1401 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1402 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1403 | } |
| 1404 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1405 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1406 | shell_surface_set_fullscreen(struct wl_client *client, |
Kristian Høgsberg | f856fd2 | 2012-02-16 15:58:14 -0500 | [diff] [blame] | 1407 | struct wl_resource *resource, |
| 1408 | uint32_t method, |
| 1409 | uint32_t framerate, |
| 1410 | struct wl_resource *output_resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1411 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1412 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1413 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1414 | |
| 1415 | if (output_resource) |
| 1416 | shsurf->output = output_resource->data; |
| 1417 | else |
| 1418 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1419 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1420 | shsurf->fullscreen_output = shsurf->output; |
| 1421 | shsurf->fullscreen.type = method; |
| 1422 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1423 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1424 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1425 | shsurf->client->send_configure(shsurf->surface, 0, |
| 1426 | shsurf->output->current->width, |
| 1427 | shsurf->output->current->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1428 | } |
| 1429 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1430 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1431 | popup_grab_focus(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1432 | struct wl_surface *surface, |
| 1433 | wl_fixed_t x, |
| 1434 | wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1435 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1436 | struct wl_pointer *pointer = grab->pointer; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1437 | struct shell_surface *priv = |
| 1438 | container_of(grab, struct shell_surface, popup.grab); |
| 1439 | struct wl_client *client = priv->surface->surface.resource.client; |
| 1440 | |
Pekka Paalanen | cb10843 | 2012-01-19 16:25:40 +0200 | [diff] [blame] | 1441 | if (surface && surface->resource.client == client) { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1442 | wl_pointer_set_focus(pointer, surface, x, y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1443 | grab->focus = surface; |
| 1444 | } else { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1445 | wl_pointer_set_focus(pointer, NULL, |
| 1446 | wl_fixed_from_int(0), |
| 1447 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1448 | grab->focus = NULL; |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1453 | popup_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1454 | uint32_t time, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1455 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1456 | struct wl_resource *resource; |
| 1457 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1458 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1459 | if (resource) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1460 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1464 | popup_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1465 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1466 | { |
| 1467 | struct wl_resource *resource; |
| 1468 | struct shell_surface *shsurf = |
| 1469 | container_of(grab, struct shell_surface, popup.grab); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1470 | struct wl_display *display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1471 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1472 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1473 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1474 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1475 | if (resource) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1476 | display = wl_client_get_display(resource->client); |
| 1477 | serial = wl_display_get_serial(display); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1478 | wl_pointer_send_button(resource, serial, time, button, state); |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1479 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1480 | (shsurf->popup.initial_up || |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1481 | time - shsurf->popup.seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1482 | wl_shell_surface_send_popup_done(&shsurf->resource); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1483 | wl_pointer_end_grab(grab->pointer); |
| 1484 | shsurf->popup.grab.pointer = NULL; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1485 | } |
| 1486 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1487 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1488 | shsurf->popup.initial_up = 1; |
| 1489 | } |
| 1490 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1491 | static const struct wl_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1492 | popup_grab_focus, |
| 1493 | popup_grab_motion, |
| 1494 | popup_grab_button, |
| 1495 | }; |
| 1496 | |
| 1497 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1498 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1499 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1500 | struct wl_seat *seat = shsurf->popup.seat; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1501 | struct weston_surface *es = shsurf->surface; |
| 1502 | struct weston_surface *parent = shsurf->parent->surface; |
| 1503 | |
| 1504 | es->output = parent->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1505 | shsurf->popup.grab.interface = &popup_grab_interface; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1506 | |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 1507 | weston_surface_update_transform(parent); |
| 1508 | if (parent->transform.enabled) { |
| 1509 | shsurf->popup.parent_transform.matrix = |
| 1510 | parent->transform.matrix; |
| 1511 | } else { |
| 1512 | /* construct x, y translation matrix */ |
| 1513 | weston_matrix_init(&shsurf->popup.parent_transform.matrix); |
| 1514 | shsurf->popup.parent_transform.matrix.d[12] = |
| 1515 | parent->geometry.x; |
| 1516 | shsurf->popup.parent_transform.matrix.d[13] = |
| 1517 | parent->geometry.y; |
| 1518 | } |
| 1519 | wl_list_insert(es->geometry.transformation_list.prev, |
| 1520 | &shsurf->popup.parent_transform.link); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1521 | weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1522 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1523 | shsurf->popup.initial_up = 0; |
| 1524 | |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1525 | /* We don't require the grab to still be active, but if another |
| 1526 | * grab has started in the meantime, we end the popup now. */ |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1527 | if (seat->pointer->grab_serial == shsurf->popup.serial) { |
| 1528 | wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1529 | } else { |
| 1530 | wl_shell_surface_send_popup_done(&shsurf->resource); |
| 1531 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | static void |
| 1535 | shell_surface_set_popup(struct wl_client *client, |
| 1536 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1537 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1538 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1539 | struct wl_resource *parent_resource, |
| 1540 | int32_t x, int32_t y, uint32_t flags) |
| 1541 | { |
| 1542 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1543 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1544 | shsurf->type = SHELL_SURFACE_POPUP; |
| 1545 | shsurf->parent = parent_resource->data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1546 | shsurf->popup.seat = seat_resource->data; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1547 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1548 | shsurf->popup.x = x; |
| 1549 | shsurf->popup.y = y; |
| 1550 | } |
| 1551 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1552 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1553 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1554 | shell_surface_move, |
| 1555 | shell_surface_resize, |
| 1556 | shell_surface_set_toplevel, |
| 1557 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1558 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1559 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1560 | shell_surface_set_maximized, |
| 1561 | shell_surface_set_title, |
| 1562 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1563 | }; |
| 1564 | |
| 1565 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1566 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1567 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1568 | if (shsurf->popup.grab.pointer) |
| 1569 | wl_pointer_end_grab(shsurf->popup.grab.pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1570 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1571 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1572 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1573 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1574 | shsurf->fullscreen_output->origin); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1575 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1576 | |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 1577 | if (shsurf->fullscreen.black_surface) |
| 1578 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
| 1579 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1580 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 1581 | * we can always remove the listener. |
| 1582 | */ |
| 1583 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 1584 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1585 | ping_timer_destroy(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1586 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1587 | wl_list_remove(&shsurf->link); |
| 1588 | free(shsurf); |
| 1589 | } |
| 1590 | |
| 1591 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1592 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 1593 | { |
| 1594 | struct shell_surface *shsurf = resource->data; |
| 1595 | |
| 1596 | destroy_shell_surface(shsurf); |
| 1597 | } |
| 1598 | |
| 1599 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1600 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1601 | { |
| 1602 | struct shell_surface *shsurf = container_of(listener, |
| 1603 | struct shell_surface, |
| 1604 | surface_destroy_listener); |
| 1605 | |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1606 | if (shsurf->resource.client) { |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1607 | wl_resource_destroy(&shsurf->resource); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1608 | } else { |
| 1609 | wl_signal_emit(&shsurf->resource.destroy_signal, |
| 1610 | &shsurf->resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1611 | destroy_shell_surface(shsurf); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1612 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1613 | } |
| 1614 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1615 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1616 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1617 | { |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1618 | struct wl_listener *listener; |
| 1619 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1620 | listener = wl_signal_get(&surface->surface.resource.destroy_signal, |
| 1621 | shell_handle_surface_destroy); |
| 1622 | if (listener) |
| 1623 | return container_of(listener, struct shell_surface, |
| 1624 | surface_destroy_listener); |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1625 | |
| 1626 | return NULL; |
| 1627 | } |
| 1628 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1629 | static void |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1630 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
| 1631 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1632 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1633 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 1634 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1635 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1636 | struct shell_surface *shsurf; |
| 1637 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1638 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1639 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1640 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1641 | } |
| 1642 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1643 | shsurf = calloc(1, sizeof *shsurf); |
| 1644 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1645 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1646 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1647 | } |
| 1648 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1649 | surface->configure = shell_surface_configure; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1650 | surface->compositor->shell_interface.shell = shell; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1651 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1652 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1653 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1654 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1655 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1656 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1657 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 1658 | shsurf->fullscreen.framerate = 0; |
| 1659 | shsurf->fullscreen.black_surface = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1660 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1661 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 1662 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1663 | wl_signal_init(&shsurf->resource.destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1664 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
| 1665 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 1666 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1667 | |
| 1668 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 1669 | wl_list_init(&shsurf->link); |
| 1670 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1671 | /* empty when not in use */ |
| 1672 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1673 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1674 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 1675 | wl_list_init(&shsurf->workspace_transform.link); |
| 1676 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1677 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1678 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1679 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1680 | shsurf->client = client; |
| 1681 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1682 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | static void |
| 1686 | shell_get_shell_surface(struct wl_client *client, |
| 1687 | struct wl_resource *resource, |
| 1688 | uint32_t id, |
| 1689 | struct wl_resource *surface_resource) |
| 1690 | { |
| 1691 | struct weston_surface *surface = surface_resource->data; |
| 1692 | struct desktop_shell *shell = resource->data; |
| 1693 | struct shell_surface *shsurf; |
| 1694 | |
| 1695 | if (get_shell_surface(surface)) { |
| 1696 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1697 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1698 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1699 | return; |
| 1700 | } |
| 1701 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1702 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1703 | if (!shsurf) { |
| 1704 | wl_resource_post_error(surface_resource, |
| 1705 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1706 | "surface->configure already set"); |
| 1707 | return; |
| 1708 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1709 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1710 | shsurf->resource.destroy = shell_destroy_shell_surface; |
| 1711 | shsurf->resource.object.id = id; |
| 1712 | shsurf->resource.object.interface = &wl_shell_surface_interface; |
| 1713 | shsurf->resource.object.implementation = |
| 1714 | (void (**)(void)) &shell_surface_implementation; |
| 1715 | shsurf->resource.data = shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1716 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1717 | wl_client_add_resource(client, &shsurf->resource); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 1721 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1722 | }; |
| 1723 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1724 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1725 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1726 | { |
| 1727 | proc->pid = 0; |
| 1728 | } |
| 1729 | |
| 1730 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1731 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1732 | { |
| 1733 | if (shell->screensaver.binding) |
| 1734 | return; |
| 1735 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1736 | if (!shell->screensaver.path) |
| 1737 | return; |
| 1738 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 1739 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1740 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 1741 | return; |
| 1742 | } |
| 1743 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1744 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1745 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1746 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1747 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1751 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1752 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1753 | if (shell->screensaver.process.pid == 0) |
| 1754 | return; |
| 1755 | |
| 1756 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1760 | show_screensaver(struct desktop_shell *shell, struct shell_surface *surface) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1761 | { |
| 1762 | struct wl_list *list; |
| 1763 | |
| 1764 | if (shell->lock_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1765 | list = &shell->lock_surface->surface->layer_link; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1766 | else |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1767 | list = &shell->lock_layer.surface_list; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1768 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1769 | wl_list_remove(&surface->surface->layer_link); |
| 1770 | wl_list_insert(list, &surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1771 | surface->surface->output = surface->output; |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 1772 | weston_surface_damage(surface->surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1776 | hide_screensaver(struct desktop_shell *shell, struct shell_surface *surface) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1777 | { |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1778 | wl_list_remove(&surface->surface->layer_link); |
| 1779 | wl_list_init(&surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1780 | surface->surface->output = NULL; |
| 1781 | } |
| 1782 | |
| 1783 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1784 | desktop_shell_set_background(struct wl_client *client, |
| 1785 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1786 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1787 | struct wl_resource *surface_resource) |
| 1788 | { |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1789 | struct shell_surface *shsurf = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1790 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1791 | shsurf->next_type = SHELL_SURFACE_BACKGROUND; |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1792 | shsurf->output = output_resource->data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1793 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1794 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1795 | surface_resource, |
| 1796 | shsurf->output->current->width, |
| 1797 | shsurf->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | static void |
| 1801 | desktop_shell_set_panel(struct wl_client *client, |
| 1802 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1803 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1804 | struct wl_resource *surface_resource) |
| 1805 | { |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1806 | struct shell_surface *shsurf = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1807 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1808 | shsurf->next_type = SHELL_SURFACE_PANEL; |
Pekka Paalanen | 068ae94 | 2011-11-28 14:11:15 +0200 | [diff] [blame] | 1809 | shsurf->output = output_resource->data; |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1810 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1811 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1812 | surface_resource, |
| 1813 | shsurf->output->current->width, |
| 1814 | shsurf->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1815 | } |
| 1816 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1817 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1818 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1819 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1820 | struct desktop_shell *shell = |
| 1821 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1822 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1823 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1824 | shell->lock_surface = NULL; |
| 1825 | } |
| 1826 | |
| 1827 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1828 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 1829 | struct wl_resource *resource, |
| 1830 | struct wl_resource *surface_resource) |
| 1831 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1832 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1833 | struct shell_surface *surface = surface_resource->data; |
| 1834 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1835 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1836 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1837 | if (!shell->locked) |
| 1838 | return; |
| 1839 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1840 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1841 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1842 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
| 1843 | wl_signal_add(&surface_resource->destroy_signal, |
| 1844 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1845 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1846 | shell->lock_surface->next_type = SHELL_SURFACE_LOCK; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1850 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1851 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1852 | struct shell_surface *tmp; |
| 1853 | |
| 1854 | wl_list_for_each(tmp, &shell->screensaver.surfaces, link) |
| 1855 | hide_screensaver(shell, tmp); |
| 1856 | |
| 1857 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1858 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1859 | wl_list_remove(&shell->lock_layer.link); |
| 1860 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 1861 | &shell->fullscreen_layer.link); |
| 1862 | wl_list_insert(&shell->fullscreen_layer.link, |
| 1863 | &shell->panel_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1864 | |
| 1865 | shell->locked = false; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 1866 | shell->compositor->idle_time = shell->compositor->option_idle_time; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1867 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 1868 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | static void |
| 1872 | desktop_shell_unlock(struct wl_client *client, |
| 1873 | struct wl_resource *resource) |
| 1874 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1875 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1876 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1877 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1878 | |
| 1879 | if (shell->locked) |
| 1880 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1881 | } |
| 1882 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1883 | static void |
| 1884 | desktop_shell_set_busy_surface(struct wl_client *client, |
| 1885 | struct wl_resource *resource, |
| 1886 | struct wl_resource *surface_resource) |
| 1887 | { |
| 1888 | struct desktop_shell *shell = resource->data; |
| 1889 | |
| 1890 | shell->busy_surface = surface_resource->data; |
| 1891 | } |
| 1892 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1893 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 1894 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1895 | desktop_shell_set_panel, |
| 1896 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 1897 | desktop_shell_unlock, |
| 1898 | desktop_shell_set_busy_surface |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1899 | }; |
| 1900 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1901 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1902 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1903 | { |
| 1904 | struct shell_surface *shsurf; |
| 1905 | |
| 1906 | shsurf = get_shell_surface(surface); |
| 1907 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1908 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1909 | return shsurf->type; |
| 1910 | } |
| 1911 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1912 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 1913 | move_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1914 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1915 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1916 | (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 1917 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 1918 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1919 | if (surface == NULL) |
| 1920 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1921 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 1922 | shsurf = get_shell_surface(surface); |
| 1923 | if (shsurf == NULL) |
| 1924 | return; |
| 1925 | |
| 1926 | switch (shsurf->type) { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1927 | case SHELL_SURFACE_PANEL: |
| 1928 | case SHELL_SURFACE_BACKGROUND: |
| 1929 | case SHELL_SURFACE_FULLSCREEN: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1930 | case SHELL_SURFACE_SCREENSAVER: |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1931 | return; |
| 1932 | default: |
| 1933 | break; |
| 1934 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 1935 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 1936 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 1940 | resize_binding(struct wl_seat *seat, uint32_t time, uint32_t button, void *data) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1941 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1942 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1943 | (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1944 | uint32_t edges = 0; |
| 1945 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1946 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 1947 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1948 | if (surface == NULL) |
| 1949 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1950 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1951 | shsurf = get_shell_surface(surface); |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 1952 | if (!shsurf) |
| 1953 | return; |
| 1954 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1955 | switch (shsurf->type) { |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1956 | case SHELL_SURFACE_PANEL: |
| 1957 | case SHELL_SURFACE_BACKGROUND: |
| 1958 | case SHELL_SURFACE_FULLSCREEN: |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1959 | case SHELL_SURFACE_SCREENSAVER: |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1960 | return; |
| 1961 | default: |
| 1962 | break; |
| 1963 | } |
Kristian Høgsberg | 10f097e | 2011-04-13 11:52:54 -0400 | [diff] [blame] | 1964 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 1965 | weston_surface_from_global(surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1966 | wl_fixed_to_int(seat->pointer->grab_x), |
| 1967 | wl_fixed_to_int(seat->pointer->grab_y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1968 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1969 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1970 | if (x < surface->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1971 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1972 | else if (x < 2 * surface->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1973 | edges |= 0; |
| 1974 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1975 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1976 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1977 | if (y < surface->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1978 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 1979 | else if (y < 2 * surface->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1980 | edges |= 0; |
| 1981 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1982 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1983 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 1984 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 1988 | surface_opacity_binding(struct wl_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 1989 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 1990 | { |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 1991 | float step = 0.05; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 1992 | struct shell_surface *shsurf; |
| 1993 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1994 | (struct weston_surface *) seat->pointer->focus; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 1995 | |
| 1996 | if (surface == NULL) |
| 1997 | return; |
| 1998 | |
| 1999 | shsurf = get_shell_surface(surface); |
| 2000 | if (!shsurf) |
| 2001 | return; |
| 2002 | |
| 2003 | switch (shsurf->type) { |
| 2004 | case SHELL_SURFACE_BACKGROUND: |
| 2005 | case SHELL_SURFACE_SCREENSAVER: |
| 2006 | return; |
| 2007 | default: |
| 2008 | break; |
| 2009 | } |
| 2010 | |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2011 | surface->alpha += wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2012 | |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2013 | if (surface->alpha > 1.0) |
| 2014 | surface->alpha = 1.0; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2015 | if (surface->alpha < step) |
| 2016 | surface->alpha = step; |
| 2017 | |
| 2018 | surface->geometry.dirty = 1; |
| 2019 | weston_surface_damage(surface); |
| 2020 | } |
| 2021 | |
| 2022 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2023 | do_zoom(struct wl_seat *seat, uint32_t time, uint32_t key, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2024 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2025 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2026 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 2027 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2028 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2029 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2030 | |
| 2031 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2032 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2033 | wl_fixed_to_double(seat->pointer->x), |
| 2034 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2035 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2036 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2037 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2038 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2039 | increment = -output->zoom.increment; |
| 2040 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2041 | increment = output->zoom.increment * |
| 2042 | wl_fixed_to_double(value); |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2043 | else |
| 2044 | increment = 0; |
| 2045 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2046 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 2047 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2048 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2049 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2050 | else if (output->zoom.level > output->zoom.max_level) |
| 2051 | output->zoom.level = output->zoom.max_level; |
| 2052 | else |
| 2053 | output->zoom.active = 1; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2054 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2055 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2056 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2057 | weston_output_update_zoom(output, |
| 2058 | seat->pointer->x, |
Scott Moreau | 7a1b32a | 2012-05-27 14:25:02 -0600 | [diff] [blame] | 2059 | seat->pointer->y, |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2060 | ZOOM_FOCUS_POINTER); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | } |
| 2064 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2065 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2066 | zoom_axis_binding(struct wl_seat *seat, uint32_t time, uint32_t axis, |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2067 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2068 | { |
| 2069 | do_zoom(seat, time, 0, axis, value); |
| 2070 | } |
| 2071 | |
| 2072 | static void |
| 2073 | zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2074 | void *data) |
| 2075 | { |
| 2076 | do_zoom(seat, time, key, 0, 0); |
| 2077 | } |
| 2078 | |
| 2079 | static void |
| 2080 | terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2081 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2082 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2083 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2084 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2085 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2089 | rotate_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2090 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2091 | { |
| 2092 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2093 | container_of(grab, struct rotate_grab, base.grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2094 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2095 | struct shell_surface *shsurf = rotate->base.shsurf; |
| 2096 | struct weston_surface *surface; |
| 2097 | GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
| 2098 | |
| 2099 | if (!shsurf) |
| 2100 | return; |
| 2101 | |
| 2102 | surface = shsurf->surface; |
| 2103 | |
| 2104 | cx = 0.5f * surface->geometry.width; |
| 2105 | cy = 0.5f * surface->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2106 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2107 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 2108 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2109 | r = sqrtf(dx * dx + dy * dy); |
| 2110 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2111 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2112 | shsurf->surface->geometry.dirty = 1; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2113 | |
| 2114 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2115 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2116 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2117 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2118 | weston_matrix_init(&rotate->rotation); |
| 2119 | rotate->rotation.d[0] = dx / r; |
| 2120 | rotate->rotation.d[4] = -dy / r; |
| 2121 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 2122 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2123 | |
| 2124 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2125 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2126 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2127 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2128 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2129 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 2130 | wl_list_insert( |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2131 | &shsurf->surface->geometry.transformation_list, |
| 2132 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2133 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2134 | wl_list_init(&shsurf->rotation.transform.link); |
| 2135 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2136 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2137 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2138 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2139 | /* We need to adjust the position of the surface |
| 2140 | * in case it was resized in a rotated state before */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2141 | cposx = surface->geometry.x + cx; |
| 2142 | cposy = surface->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2143 | dposx = rotate->center.x - cposx; |
| 2144 | dposy = rotate->center.y - cposy; |
| 2145 | if (dposx != 0.0f || dposy != 0.0f) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2146 | weston_surface_set_position(surface, |
| 2147 | surface->geometry.x + dposx, |
| 2148 | surface->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2149 | } |
| 2150 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2151 | /* Repaint implies weston_surface_update_transform(), which |
| 2152 | * lazily applies the damage due to rotation update. |
| 2153 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2154 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2158 | rotate_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2159 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2160 | { |
| 2161 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2162 | container_of(grab, struct rotate_grab, base.grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2163 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2164 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2165 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2166 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2167 | if (pointer->button_count == 0 && |
| 2168 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2169 | if (shsurf) |
| 2170 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 2171 | &rotate->rotation); |
| 2172 | shell_grab_finish(&rotate->base); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2173 | wl_pointer_end_grab(pointer); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2174 | free(rotate); |
| 2175 | } |
| 2176 | } |
| 2177 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2178 | static const struct wl_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2179 | noop_grab_focus, |
| 2180 | rotate_grab_motion, |
| 2181 | rotate_grab_button, |
| 2182 | }; |
| 2183 | |
| 2184 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2185 | rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, |
Daniel Stone | e5a0120 | 2012-05-04 11:21:57 +0100 | [diff] [blame] | 2186 | void *data) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2187 | { |
| 2188 | struct weston_surface *base_surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2189 | (struct weston_surface *) seat->pointer->focus; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2190 | struct shell_surface *surface; |
| 2191 | struct rotate_grab *rotate; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2192 | GLfloat dx, dy; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2193 | GLfloat r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2194 | |
| 2195 | if (base_surface == NULL) |
| 2196 | return; |
| 2197 | |
| 2198 | surface = get_shell_surface(base_surface); |
| 2199 | if (!surface) |
| 2200 | return; |
| 2201 | |
| 2202 | switch (surface->type) { |
| 2203 | case SHELL_SURFACE_PANEL: |
| 2204 | case SHELL_SURFACE_BACKGROUND: |
| 2205 | case SHELL_SURFACE_FULLSCREEN: |
| 2206 | case SHELL_SURFACE_SCREENSAVER: |
| 2207 | return; |
| 2208 | default: |
| 2209 | break; |
| 2210 | } |
| 2211 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2212 | rotate = malloc(sizeof *rotate); |
| 2213 | if (!rotate) |
| 2214 | return; |
| 2215 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2216 | shell_grab_init(&rotate->base, &rotate_grab_interface, surface); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 2217 | |
Kristian Høgsberg | b2af93e | 2012-06-07 20:10:23 -0400 | [diff] [blame] | 2218 | weston_surface_to_global_float(surface->surface, |
| 2219 | surface->surface->geometry.width / 2, |
| 2220 | surface->surface->geometry.height / 2, |
| 2221 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2222 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2223 | wl_pointer_start_grab(seat->pointer, &rotate->base.grab); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2224 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2225 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 2226 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2227 | r = sqrtf(dx * dx + dy * dy); |
| 2228 | if (r > 20.0f) { |
| 2229 | struct weston_matrix inverse; |
| 2230 | |
| 2231 | weston_matrix_init(&inverse); |
| 2232 | inverse.d[0] = dx / r; |
| 2233 | inverse.d[4] = dy / r; |
| 2234 | inverse.d[1] = -inverse.d[4]; |
| 2235 | inverse.d[5] = inverse.d[0]; |
| 2236 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2237 | |
| 2238 | weston_matrix_init(&rotate->rotation); |
| 2239 | rotate->rotation.d[0] = dx / r; |
| 2240 | rotate->rotation.d[4] = -dy / r; |
| 2241 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 2242 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2243 | } else { |
| 2244 | weston_matrix_init(&surface->rotation.rotation); |
| 2245 | weston_matrix_init(&rotate->rotation); |
| 2246 | } |
| 2247 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2248 | wl_pointer_set_focus(seat->pointer, NULL, |
| 2249 | wl_fixed_from_int(0), |
| 2250 | wl_fixed_from_int(0)); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2254 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2255 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2256 | { |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2257 | struct weston_surface *surf, *prev; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2258 | struct workspace *ws; |
| 2259 | struct weston_layer *ws_layer; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2260 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2261 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2262 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2263 | switch (get_shell_surface_type(es)) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2264 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2265 | case SHELL_SURFACE_PANEL: |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2266 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2267 | break; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2268 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2269 | case SHELL_SURFACE_SCREENSAVER: |
| 2270 | /* always below lock surface */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2271 | if (shell->lock_surface) |
| 2272 | weston_surface_restack(es, |
| 2273 | &shell->lock_surface->surface->layer_link); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2274 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2275 | case SHELL_SURFACE_FULLSCREEN: |
| 2276 | /* should on top of panels */ |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2277 | shell_stack_fullscreen(get_shell_surface(es)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2278 | shell_configure_fullscreen(get_shell_surface(es)); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2279 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2280 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2281 | ws = get_current_workspace(shell); |
| 2282 | ws_layer = &ws->layer; |
| 2283 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2284 | /* move the fullscreen surfaces down into the toplevel layer */ |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2285 | if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) { |
| 2286 | wl_list_for_each_reverse_safe(surf, |
| 2287 | prev, |
| 2288 | &shell->fullscreen_layer.surface_list, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2289 | layer_link) { |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2290 | weston_surface_restack(surf, |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2291 | &ws_layer->surface_list); |
| 2292 | } |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2293 | } |
| 2294 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2295 | weston_surface_restack(es, &ws_layer->surface_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2296 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2297 | } |
| 2298 | } |
| 2299 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2300 | /* no-op func for checking black surface */ |
| 2301 | static void |
| 2302 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2303 | { |
| 2304 | } |
| 2305 | |
| 2306 | static bool |
| 2307 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 2308 | { |
| 2309 | if (es->configure == black_surface_configure) { |
| 2310 | if (fs_surface) |
| 2311 | *fs_surface = (struct weston_surface *)es->private; |
| 2312 | return true; |
| 2313 | } |
| 2314 | return false; |
| 2315 | } |
| 2316 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2317 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2318 | click_to_activate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2319 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2320 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2321 | struct weston_seat *ws = (struct weston_seat *) seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2322 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2323 | struct weston_surface *focus; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2324 | struct weston_surface *upper; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2325 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2326 | focus = (struct weston_surface *) seat->pointer->focus; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 2327 | if (!focus) |
| 2328 | return; |
| 2329 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2330 | if (is_black_surface(focus, &upper)) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2331 | focus = upper; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2332 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2333 | if (seat->pointer->grab == &seat->pointer->default_grab) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2334 | activate(shell, focus, ws); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2338 | lock(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2339 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2340 | struct desktop_shell *shell = |
| 2341 | container_of(listener, struct desktop_shell, lock_listener); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2342 | struct weston_seat *seat; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2343 | struct shell_surface *shsurf; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2344 | struct weston_output *output; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2345 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2346 | if (shell->locked) { |
| 2347 | wl_list_for_each(output, &shell->compositor->output_list, link) |
| 2348 | /* TODO: find a way to jump to other DPMS levels */ |
| 2349 | if (output->set_dpms) |
| 2350 | output->set_dpms(output, WESTON_DPMS_STANDBY); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2351 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2352 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2353 | |
| 2354 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2355 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2356 | /* Hide all surfaces by removing the fullscreen, panel and |
| 2357 | * toplevel layers. This way nothing else can show or receive |
| 2358 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2359 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2360 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2361 | wl_list_remove(&shell->fullscreen_layer.link); |
| 2362 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 2363 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2364 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2365 | launch_screensaver(shell); |
| 2366 | |
| 2367 | wl_list_for_each(shsurf, &shell->screensaver.surfaces, link) |
| 2368 | show_screensaver(shell, shsurf); |
| 2369 | |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2370 | if (!wl_list_empty(&shell->screensaver.surfaces)) { |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 2371 | shell->compositor->idle_time = shell->screensaver.duration; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2372 | weston_compositor_wake(shell->compositor); |
| 2373 | shell->compositor->state = WESTON_COMPOSITOR_IDLE; |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2374 | } |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 2375 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2376 | /* reset pointer foci */ |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2377 | weston_compositor_schedule_repaint(shell->compositor); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2378 | |
| 2379 | /* reset keyboard foci */ |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2380 | wl_list_for_each(seat, &shell->compositor->seat_list, link) { |
| 2381 | wl_keyboard_set_focus(seat->seat.keyboard, NULL); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | /* TODO: disable bindings that should not work while locked. */ |
| 2385 | |
| 2386 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2390 | unlock(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2391 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2392 | struct desktop_shell *shell = |
| 2393 | container_of(listener, struct desktop_shell, unlock_listener); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2394 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 2395 | if (!shell->locked || shell->lock_surface) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2396 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2397 | return; |
| 2398 | } |
| 2399 | |
| 2400 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 2401 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2402 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2403 | return; |
| 2404 | } |
| 2405 | |
| 2406 | if (shell->prepare_event_sent) |
| 2407 | return; |
| 2408 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2409 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2410 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2414 | center_on_output(struct weston_surface *surface, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2415 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2416 | struct weston_mode *mode = output->current; |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 2417 | GLfloat x = (mode->width - surface->geometry.width) / 2; |
| 2418 | GLfloat y = (mode->height - surface->geometry.height) / 2; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2419 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 2420 | weston_surface_set_position(surface, output->x + x, output->y + y); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2421 | } |
| 2422 | |
| 2423 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2424 | map(struct desktop_shell *shell, struct weston_surface *surface, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 2425 | 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] | 2426 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2427 | struct weston_compositor *compositor = shell->compositor; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2428 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 2429 | enum shell_surface_type surface_type = shsurf->type; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 2430 | struct weston_surface *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 2431 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2432 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2433 | int panel_height = 0; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2434 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2435 | surface->geometry.width = width; |
| 2436 | surface->geometry.height = height; |
| 2437 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2438 | |
| 2439 | /* initial positioning, see also configure() */ |
| 2440 | switch (surface_type) { |
| 2441 | case SHELL_SURFACE_TOPLEVEL: |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 2442 | weston_surface_set_position(surface, 10 + random() % 400, |
| 2443 | 10 + random() % 400); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2444 | break; |
| 2445 | case SHELL_SURFACE_SCREENSAVER: |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 2446 | center_on_output(surface, shsurf->fullscreen_output); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2447 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2448 | case SHELL_SURFACE_FULLSCREEN: |
| 2449 | shell_map_fullscreen(shsurf); |
| 2450 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2451 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2452 | /* use surface configure to set the geometry */ |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2453 | panel_height = get_output_panel_height(shell,surface->output); |
| 2454 | weston_surface_set_position(surface, surface->output->x, |
| 2455 | surface->output->y + panel_height); |
| 2456 | break; |
Pekka Paalanen | af0e34c | 2011-12-02 10:59:17 +0200 | [diff] [blame] | 2457 | case SHELL_SURFACE_LOCK: |
| 2458 | center_on_output(surface, get_default_output(compositor)); |
| 2459 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 2460 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2461 | shell_map_popup(shsurf); |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 2462 | case SHELL_SURFACE_NONE: |
| 2463 | weston_surface_set_position(surface, |
| 2464 | surface->geometry.x + sx, |
| 2465 | surface->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 2466 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2467 | default: |
| 2468 | ; |
| 2469 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2470 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 2471 | /* surface stacking order, see also activate() */ |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2472 | switch (surface_type) { |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2473 | case SHELL_SURFACE_BACKGROUND: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 2474 | /* background always visible, at the bottom */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2475 | wl_list_insert(&shell->background_layer.surface_list, |
| 2476 | &surface->layer_link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2477 | break; |
| 2478 | case SHELL_SURFACE_PANEL: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 2479 | /* panel always on top, hidden while locked */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2480 | wl_list_insert(&shell->panel_layer.surface_list, |
| 2481 | &surface->layer_link); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2482 | break; |
| 2483 | case SHELL_SURFACE_LOCK: |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 2484 | /* lock surface always visible, on top */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2485 | wl_list_insert(&shell->lock_layer.surface_list, |
| 2486 | &surface->layer_link); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2487 | weston_compositor_wake(compositor); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2488 | break; |
| 2489 | case SHELL_SURFACE_SCREENSAVER: |
| 2490 | /* If locked, show it. */ |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 2491 | if (shell->locked) { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2492 | show_screensaver(shell, shsurf); |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 2493 | compositor->idle_time = shell->screensaver.duration; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2494 | weston_compositor_wake(compositor); |
Pekka Paalanen | bce2d3f | 2011-12-02 13:07:27 +0200 | [diff] [blame] | 2495 | if (!shell->lock_surface) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2496 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Pekka Paalanen | baeb6a1 | 2011-12-01 16:23:57 +0200 | [diff] [blame] | 2497 | } |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2498 | break; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 2499 | case SHELL_SURFACE_POPUP: |
| 2500 | case SHELL_SURFACE_TRANSIENT: |
| 2501 | parent = shsurf->parent->surface; |
| 2502 | wl_list_insert(parent->layer_link.prev, &surface->layer_link); |
| 2503 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2504 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 2505 | case SHELL_SURFACE_NONE: |
| 2506 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2507 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2508 | ws = get_current_workspace(shell); |
| 2509 | wl_list_insert(&ws->layer.surface_list, &surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2510 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2511 | } |
| 2512 | |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 2513 | if (surface_type != SHELL_SURFACE_NONE) { |
| 2514 | weston_surface_assign_output(surface); |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 2515 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 2516 | surface->output = shsurf->output; |
| 2517 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 2518 | |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2519 | switch (surface_type) { |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2520 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 2521 | if (shsurf->transient.flags == |
| 2522 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 2523 | break; |
| 2524 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2525 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2526 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 2527 | if (!shell->locked) { |
| 2528 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 2529 | activate(shell, surface, seat); |
| 2530 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2531 | break; |
| 2532 | default: |
| 2533 | break; |
| 2534 | } |
| 2535 | |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 2536 | if (surface_type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 2537 | { |
| 2538 | switch (shell->win_animation_type) { |
| 2539 | case ANIMATION_FADE: |
| 2540 | weston_fade_run(surface, NULL, NULL); |
| 2541 | break; |
| 2542 | case ANIMATION_ZOOM: |
| 2543 | weston_zoom_run(surface, 0.8, 1.0, NULL, NULL); |
| 2544 | break; |
| 2545 | default: |
| 2546 | break; |
| 2547 | } |
| 2548 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2552 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 2553 | GLfloat x, GLfloat y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2554 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2555 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 2556 | struct shell_surface *shsurf; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2557 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2558 | shsurf = get_shell_surface(surface); |
| 2559 | if (shsurf) |
| 2560 | surface_type = shsurf->type; |
| 2561 | |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2562 | surface->geometry.x = x; |
| 2563 | surface->geometry.y = y; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2564 | surface->geometry.width = width; |
| 2565 | surface->geometry.height = height; |
| 2566 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2567 | |
| 2568 | switch (surface_type) { |
| 2569 | case SHELL_SURFACE_SCREENSAVER: |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 2570 | center_on_output(surface, shsurf->fullscreen_output); |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2571 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2572 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2573 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2574 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2575 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2576 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2577 | /* setting x, y and using configure to change that geometry */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2578 | surface->geometry.x = surface->output->x; |
| 2579 | surface->geometry.y = surface->output->y + |
| 2580 | get_output_panel_height(shell,surface->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2581 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2582 | case SHELL_SURFACE_TOPLEVEL: |
| 2583 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2584 | default: |
| 2585 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2586 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2587 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2588 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2589 | if (surface->output) { |
Pekka Paalanen | f07cb5d | 2012-02-10 13:34:36 +0200 | [diff] [blame] | 2590 | weston_surface_assign_output(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2591 | |
| 2592 | if (surface_type == SHELL_SURFACE_SCREENSAVER) |
| 2593 | surface->output = shsurf->output; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2594 | else if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 2595 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2596 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2597 | } |
| 2598 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2599 | static void |
| 2600 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2601 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 2602 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2603 | struct desktop_shell *shell = shsurf->shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 2604 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2605 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2606 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 2607 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2608 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 2609 | type_changed = 1; |
| 2610 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2611 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2612 | if (!weston_surface_is_mapped(es)) { |
| 2613 | map(shell, es, es->buffer->width, es->buffer->height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 2614 | } else if (type_changed || sx != 0 || sy != 0 || |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2615 | es->geometry.width != es->buffer->width || |
| 2616 | es->geometry.height != es->buffer->height) { |
| 2617 | GLfloat from_x, from_y; |
| 2618 | GLfloat to_x, to_y; |
| 2619 | |
| 2620 | weston_surface_to_global_float(es, 0, 0, &from_x, &from_y); |
| 2621 | weston_surface_to_global_float(es, sx, sy, &to_x, &to_y); |
| 2622 | configure(shell, es, |
| 2623 | es->geometry.x + to_x - from_x, |
| 2624 | es->geometry.y + to_y - from_y, |
| 2625 | es->buffer->width, es->buffer->height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2626 | } |
| 2627 | } |
| 2628 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2629 | static int launch_desktop_shell_process(struct desktop_shell *shell); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2630 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2631 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2632 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2633 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2634 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2635 | struct desktop_shell *shell = |
| 2636 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2637 | |
| 2638 | shell->child.process.pid = 0; |
| 2639 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2640 | |
| 2641 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 2642 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 2643 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2644 | shell->child.deathstamp = time; |
| 2645 | shell->child.deathcount = 0; |
| 2646 | } |
| 2647 | |
| 2648 | shell->child.deathcount++; |
| 2649 | if (shell->child.deathcount > 5) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2650 | weston_log("weston-desktop-shell died, giving up.\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2651 | return; |
| 2652 | } |
| 2653 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2654 | weston_log("weston-desktop-shell died, respawning...\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2655 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2659 | launch_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2660 | { |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 2661 | const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2662 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2663 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 2664 | &shell->child.process, |
| 2665 | shell_exe, |
| 2666 | desktop_shell_sigchld); |
| 2667 | |
| 2668 | if (!shell->child.client) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2669 | return -1; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2670 | return 0; |
| 2671 | } |
| 2672 | |
| 2673 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2674 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 2675 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2676 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2677 | |
| 2678 | wl_client_add_object(client, &wl_shell_interface, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2679 | &shell_implementation, id, shell); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2680 | } |
| 2681 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2682 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2683 | unbind_desktop_shell(struct wl_resource *resource) |
| 2684 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2685 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2686 | |
| 2687 | if (shell->locked) |
| 2688 | resume_desktop(shell); |
| 2689 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2690 | shell->child.desktop_shell = NULL; |
| 2691 | shell->prepare_event_sent = false; |
| 2692 | free(resource); |
| 2693 | } |
| 2694 | |
| 2695 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2696 | bind_desktop_shell(struct wl_client *client, |
| 2697 | void *data, uint32_t version, uint32_t id) |
| 2698 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2699 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2700 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2701 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2702 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 2703 | &desktop_shell_implementation, |
| 2704 | id, shell); |
| 2705 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2706 | if (client == shell->child.client) { |
| 2707 | resource->destroy = unbind_desktop_shell; |
| 2708 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2709 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2710 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2711 | |
| 2712 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2713 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2714 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2715 | } |
| 2716 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2717 | static void |
| 2718 | screensaver_set_surface(struct wl_client *client, |
| 2719 | struct wl_resource *resource, |
| 2720 | struct wl_resource *shell_surface_resource, |
| 2721 | struct wl_resource *output_resource) |
| 2722 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2723 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2724 | struct shell_surface *surface = shell_surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2725 | struct weston_output *output = output_resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2726 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2727 | surface->next_type = SHELL_SURFACE_SCREENSAVER; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2728 | |
Kristian Høgsberg | 1cbf326 | 2012-02-17 23:49:07 -0500 | [diff] [blame] | 2729 | surface->fullscreen_output = output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2730 | surface->output = output; |
| 2731 | wl_list_insert(shell->screensaver.surfaces.prev, &surface->link); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | static const struct screensaver_interface screensaver_implementation = { |
| 2735 | screensaver_set_surface |
| 2736 | }; |
| 2737 | |
| 2738 | static void |
| 2739 | unbind_screensaver(struct wl_resource *resource) |
| 2740 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2741 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2742 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2743 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2744 | free(resource); |
| 2745 | } |
| 2746 | |
| 2747 | static void |
| 2748 | bind_screensaver(struct wl_client *client, |
| 2749 | void *data, uint32_t version, uint32_t id) |
| 2750 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2751 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2752 | struct wl_resource *resource; |
| 2753 | |
| 2754 | resource = wl_client_add_object(client, &screensaver_interface, |
| 2755 | &screensaver_implementation, |
| 2756 | id, shell); |
| 2757 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2758 | if (shell->screensaver.binding == NULL) { |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2759 | resource->destroy = unbind_screensaver; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2760 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2761 | return; |
| 2762 | } |
| 2763 | |
| 2764 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2765 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2766 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2767 | } |
| 2768 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2769 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2770 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2771 | struct weston_surface *current; |
| 2772 | struct wl_listener listener; |
| 2773 | struct wl_keyboard_grab grab; |
| 2774 | }; |
| 2775 | |
| 2776 | static void |
| 2777 | switcher_next(struct switcher *switcher) |
| 2778 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2779 | struct weston_compositor *compositor = switcher->shell->compositor; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2780 | struct weston_surface *surface; |
| 2781 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 2782 | struct shell_surface *shsurf; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2783 | |
| 2784 | wl_list_for_each(surface, &compositor->surface_list, link) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2785 | switch (get_shell_surface_type(surface)) { |
| 2786 | case SHELL_SURFACE_TOPLEVEL: |
| 2787 | case SHELL_SURFACE_FULLSCREEN: |
| 2788 | case SHELL_SURFACE_MAXIMIZED: |
| 2789 | if (first == NULL) |
| 2790 | first = surface; |
| 2791 | if (prev == switcher->current) |
| 2792 | next = surface; |
| 2793 | prev = surface; |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2794 | surface->alpha = 0.25; |
Kristian Høgsberg | cacb7cd | 2012-02-28 09:20:21 -0500 | [diff] [blame] | 2795 | surface->geometry.dirty = 1; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2796 | weston_surface_damage(surface); |
| 2797 | break; |
| 2798 | default: |
| 2799 | break; |
| 2800 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 2801 | |
| 2802 | if (is_black_surface(surface, NULL)) { |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2803 | surface->alpha = 0.25; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 2804 | surface->geometry.dirty = 1; |
| 2805 | weston_surface_damage(surface); |
| 2806 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | if (next == NULL) |
| 2810 | next = first; |
| 2811 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 2812 | if (next == NULL) |
| 2813 | return; |
| 2814 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2815 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2816 | wl_signal_add(&next->surface.resource.destroy_signal, |
| 2817 | &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2818 | |
| 2819 | switcher->current = next; |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 2820 | next->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 2821 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 2822 | shsurf = get_shell_surface(switcher->current); |
| 2823 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 2824 | shsurf->fullscreen.black_surface->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2828 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2829 | { |
| 2830 | struct switcher *switcher = |
| 2831 | container_of(listener, struct switcher, listener); |
| 2832 | |
| 2833 | switcher_next(switcher); |
| 2834 | } |
| 2835 | |
| 2836 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 2837 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2838 | { |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2839 | struct weston_compositor *compositor = switcher->shell->compositor; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2840 | struct weston_surface *surface; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2841 | struct wl_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2842 | |
| 2843 | wl_list_for_each(surface, &compositor->surface_list, link) { |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 2844 | surface->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2845 | weston_surface_damage(surface); |
| 2846 | } |
| 2847 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 2848 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2849 | activate(switcher->shell, switcher->current, |
| 2850 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2851 | wl_list_remove(&switcher->listener.link); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2852 | wl_keyboard_end_grab(keyboard); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2853 | free(switcher); |
| 2854 | } |
| 2855 | |
| 2856 | static void |
| 2857 | switcher_key(struct wl_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 2858 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2859 | { |
| 2860 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 2861 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 2862 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 2863 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 2864 | switcher_next(switcher); |
| 2865 | } |
| 2866 | |
| 2867 | static void |
| 2868 | switcher_modifier(struct wl_keyboard_grab *grab, uint32_t serial, |
| 2869 | uint32_t mods_depressed, uint32_t mods_latched, |
| 2870 | uint32_t mods_locked, uint32_t group) |
| 2871 | { |
| 2872 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2873 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2874 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 2875 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 2876 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 2877 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2878 | |
| 2879 | static const struct wl_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 2880 | switcher_key, |
| 2881 | switcher_modifier, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2882 | }; |
| 2883 | |
| 2884 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2885 | switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2886 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2887 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2888 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2889 | struct switcher *switcher; |
| 2890 | |
| 2891 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2892 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2893 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2894 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2895 | wl_list_init(&switcher->listener.link); |
| 2896 | |
| 2897 | switcher->grab.interface = &switcher_grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2898 | wl_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 2899 | wl_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2900 | switcher_next(switcher); |
| 2901 | } |
| 2902 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 2903 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2904 | backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2905 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2906 | { |
| 2907 | struct weston_compositor *compositor = data; |
| 2908 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 2909 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2910 | |
| 2911 | /* TODO: we're limiting to simple use cases, where we assume just |
| 2912 | * control on the primary display. We'd have to extend later if we |
| 2913 | * ever get support for setting backlights on random desktop LCD |
| 2914 | * panels though */ |
| 2915 | output = get_default_output(compositor); |
| 2916 | if (!output) |
| 2917 | return; |
| 2918 | |
| 2919 | if (!output->set_backlight) |
| 2920 | return; |
| 2921 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 2922 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 2923 | backlight_new = output->backlight_current - 25; |
| 2924 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 2925 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2926 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 2927 | if (backlight_new < 5) |
| 2928 | backlight_new = 5; |
| 2929 | if (backlight_new > 255) |
| 2930 | backlight_new = 255; |
| 2931 | |
| 2932 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2933 | output->set_backlight(output, output->backlight_current); |
| 2934 | } |
| 2935 | |
| 2936 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2937 | debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2938 | void *data) |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 2939 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2940 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2941 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 2942 | struct weston_surface *surface; |
| 2943 | |
| 2944 | if (shell->debug_repaint_surface) { |
| 2945 | weston_surface_destroy(shell->debug_repaint_surface); |
| 2946 | shell->debug_repaint_surface = NULL; |
| 2947 | } else { |
| 2948 | surface = weston_surface_create(compositor); |
| 2949 | weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2); |
| 2950 | weston_surface_configure(surface, 0, 0, 8192, 8192); |
| 2951 | wl_list_insert(&compositor->fade_layer.surface_list, |
| 2952 | &surface->layer_link); |
| 2953 | weston_surface_assign_output(surface); |
| 2954 | pixman_region32_init(&surface->input); |
| 2955 | |
| 2956 | /* Here's the dirty little trick that makes the |
| 2957 | * repaint debugging work: we force an |
| 2958 | * update_transform first to update dependent state |
| 2959 | * and clear the geometry.dirty bit. Then we clear |
| 2960 | * the surface damage so it only gets repainted |
| 2961 | * piecewise as we repaint other things. */ |
| 2962 | |
| 2963 | weston_surface_update_transform(surface); |
| 2964 | pixman_region32_fini(&surface->damage); |
| 2965 | pixman_region32_init(&surface->damage); |
| 2966 | shell->debug_repaint_surface = surface; |
| 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2971 | force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2972 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 2973 | { |
| 2974 | struct wl_client *client; |
| 2975 | pid_t pid; |
| 2976 | uid_t uid; |
| 2977 | gid_t gid; |
| 2978 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2979 | client = seat->keyboard->focus->resource.client; |
| 2980 | wl_client_get_credentials(client, &pid, &uid, &gid); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 2981 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2982 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2986 | workspace_up_binding(struct wl_seat *seat, uint32_t time, |
| 2987 | uint32_t key, void *data) |
| 2988 | { |
| 2989 | struct desktop_shell *shell = data; |
| 2990 | unsigned int new_index = shell->workspaces.current; |
| 2991 | |
| 2992 | if (new_index != 0) |
| 2993 | new_index--; |
| 2994 | |
| 2995 | change_workspace(shell, new_index); |
| 2996 | } |
| 2997 | |
| 2998 | static void |
| 2999 | workspace_down_binding(struct wl_seat *seat, uint32_t time, |
| 3000 | uint32_t key, void *data) |
| 3001 | { |
| 3002 | struct desktop_shell *shell = data; |
| 3003 | unsigned int new_index = shell->workspaces.current; |
| 3004 | |
| 3005 | if (new_index < shell->workspaces.num - 1) |
| 3006 | new_index++; |
| 3007 | |
| 3008 | change_workspace(shell, new_index); |
| 3009 | } |
| 3010 | |
| 3011 | static void |
| 3012 | workspace_f_binding(struct wl_seat *seat, uint32_t time, |
| 3013 | uint32_t key, void *data) |
| 3014 | { |
| 3015 | struct desktop_shell *shell = data; |
| 3016 | unsigned int new_index; |
| 3017 | |
| 3018 | new_index = key - KEY_F1; |
| 3019 | if (new_index >= shell->workspaces.num) |
| 3020 | new_index = shell->workspaces.num - 1; |
| 3021 | |
| 3022 | change_workspace(shell, new_index); |
| 3023 | } |
| 3024 | |
| 3025 | |
| 3026 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3027 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3028 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3029 | struct desktop_shell *shell = |
| 3030 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3031 | struct workspace **ws; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3032 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 3033 | if (shell->child.client) |
| 3034 | wl_client_destroy(shell->child.client); |
| 3035 | |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 3036 | wl_list_remove(&shell->lock_listener.link); |
| 3037 | wl_list_remove(&shell->unlock_listener.link); |
| 3038 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3039 | wl_array_for_each(ws, &shell->workspaces.array) |
| 3040 | workspace_destroy(*ws); |
| 3041 | wl_array_release(&shell->workspaces.array); |
| 3042 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3043 | free(shell->screensaver.path); |
| 3044 | free(shell); |
| 3045 | } |
| 3046 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3047 | static void |
| 3048 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 3049 | { |
| 3050 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3051 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3052 | |
| 3053 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3054 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 3055 | MODIFIER_CTRL | MODIFIER_ALT, |
| 3056 | terminate_binding, ec); |
| 3057 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 3058 | click_to_activate_binding, |
| 3059 | shell); |
| 3060 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 3061 | MODIFIER_SUPER | MODIFIER_ALT, |
| 3062 | surface_opacity_binding, NULL); |
| 3063 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 3064 | MODIFIER_SUPER, zoom_axis_binding, |
| 3065 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3066 | |
| 3067 | /* configurable bindings */ |
| 3068 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3069 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 3070 | zoom_key_binding, NULL); |
| 3071 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 3072 | zoom_key_binding, NULL); |
| 3073 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 3074 | shell); |
| 3075 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 3076 | resize_binding, shell); |
| 3077 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 3078 | rotate_binding, NULL); |
| 3079 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 3080 | shell); |
| 3081 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 3082 | ec); |
| 3083 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 3084 | backlight_binding, ec); |
| 3085 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 3086 | ec); |
| 3087 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 3088 | backlight_binding, ec); |
| 3089 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod, |
| 3090 | debug_repaint_binding, shell); |
| 3091 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 3092 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3093 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 3094 | workspace_up_binding, shell); |
| 3095 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 3096 | workspace_down_binding, shell); |
| 3097 | |
| 3098 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 3099 | if (shell->workspaces.num > 1) { |
| 3100 | num_workspace_bindings = shell->workspaces.num; |
| 3101 | if (num_workspace_bindings > 6) |
| 3102 | num_workspace_bindings = 6; |
| 3103 | for (i = 0; i < num_workspace_bindings; i++) |
| 3104 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 3105 | workspace_f_binding, |
| 3106 | shell); |
| 3107 | } |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3108 | } |
| 3109 | |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 3110 | int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3111 | shell_init(struct weston_compositor *ec); |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 3112 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3113 | WL_EXPORT int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3114 | shell_init(struct weston_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3115 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3116 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3117 | struct workspace **pws; |
| 3118 | unsigned int i; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3119 | |
| 3120 | shell = malloc(sizeof *shell); |
| 3121 | if (shell == NULL) |
| 3122 | return -1; |
| 3123 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 3124 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3125 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3126 | |
| 3127 | shell->destroy_listener.notify = shell_destroy; |
| 3128 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
| 3129 | shell->lock_listener.notify = lock; |
| 3130 | wl_signal_add(&ec->lock_signal, &shell->lock_listener); |
| 3131 | shell->unlock_listener.notify = unlock; |
| 3132 | wl_signal_add(&ec->unlock_signal, &shell->unlock_listener); |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 3133 | ec->ping_handler = ping_handler; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3134 | ec->shell_interface.create_shell_surface = create_shell_surface; |
| 3135 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 3136 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3137 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3138 | ec->shell_interface.resize = surface_resize; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3139 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 3140 | wl_list_init(&shell->backgrounds); |
| 3141 | wl_list_init(&shell->panels); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3142 | wl_list_init(&shell->screensaver.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3143 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3144 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 3145 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3146 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 3147 | weston_layer_init(&shell->lock_layer, NULL); |
| 3148 | |
| 3149 | wl_array_init(&shell->workspaces.array); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3150 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 3151 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3152 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3153 | for (i = 0; i < shell->workspaces.num; i++) { |
| 3154 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 3155 | if (pws == NULL) |
| 3156 | return -1; |
| 3157 | |
| 3158 | *pws = workspace_create(); |
| 3159 | if (*pws == NULL) |
| 3160 | return -1; |
| 3161 | } |
| 3162 | activate_workspace(shell, 0); |
| 3163 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame^] | 3164 | wl_list_init(&shell->workspaces.animation.link); |
| 3165 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 3166 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3167 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 3168 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3169 | return -1; |
| 3170 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3171 | if (wl_display_add_global(ec->wl_display, |
| 3172 | &desktop_shell_interface, |
| 3173 | shell, bind_desktop_shell) == NULL) |
| 3174 | return -1; |
| 3175 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3176 | if (wl_display_add_global(ec->wl_display, &screensaver_interface, |
| 3177 | shell, bind_screensaver) == NULL) |
| 3178 | return -1; |
| 3179 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 3180 | shell->child.deathstamp = weston_compositor_get_time(); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3181 | if (launch_desktop_shell_process(shell) != 0) |
| 3182 | return -1; |
| 3183 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3184 | shell->pointer_focus_listener.notify = handle_pointer_focus; |
Pekka Paalanen | 43e1ba8 | 2012-06-07 15:07:06 +0300 | [diff] [blame] | 3185 | if (ec->seat->seat.pointer) |
| 3186 | wl_signal_add(&ec->seat->seat.pointer->focus_signal, |
| 3187 | &shell->pointer_focus_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3188 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3189 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3190 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3191 | return 0; |
| 3192 | } |