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