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); |
| 1391 | return surface; |
| 1392 | } |
| 1393 | |
| 1394 | /* Create black surface and append it to the associated fullscreen surface. |
| 1395 | * Handle size dismatch and positioning according to the method. */ |
| 1396 | static void |
| 1397 | shell_configure_fullscreen(struct shell_surface *shsurf) |
| 1398 | { |
| 1399 | struct weston_output *output = shsurf->fullscreen_output; |
| 1400 | struct weston_surface *surface = shsurf->surface; |
| 1401 | struct weston_matrix *matrix; |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1402 | float scale, output_aspect, surface_aspect, x, y; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1403 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1404 | if (!shsurf->fullscreen.black_surface) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1405 | shsurf->fullscreen.black_surface = |
| 1406 | create_black_surface(surface->compositor, |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 1407 | surface, |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1408 | output->x, output->y, |
| 1409 | output->current->width, |
| 1410 | output->current->height); |
| 1411 | |
| 1412 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
| 1413 | wl_list_insert(&surface->layer_link, |
| 1414 | &shsurf->fullscreen.black_surface->layer_link); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1415 | shsurf->fullscreen.black_surface->output = output; |
| 1416 | |
| 1417 | switch (shsurf->fullscreen.type) { |
| 1418 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT: |
Kristian Høgsberg | a08b528 | 2012-07-20 15:30:36 -0400 | [diff] [blame] | 1419 | if (surface->buffer) |
| 1420 | center_on_output(surface, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1421 | break; |
| 1422 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE: |
| 1423 | matrix = &shsurf->fullscreen.transform.matrix; |
| 1424 | weston_matrix_init(matrix); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1425 | |
| 1426 | output_aspect = (float) output->current->width / |
| 1427 | (float) output->current->height; |
| 1428 | surface_aspect = (float) surface->geometry.width / |
| 1429 | (float) surface->geometry.height; |
| 1430 | if (output_aspect < surface_aspect) |
| 1431 | scale = (float) output->current->width / |
| 1432 | (float) surface->geometry.width; |
| 1433 | else |
| 1434 | scale = (float) output->current->height / |
| 1435 | (float) surface->geometry.height; |
| 1436 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1437 | weston_matrix_scale(matrix, scale, scale, 1); |
| 1438 | wl_list_remove(&shsurf->fullscreen.transform.link); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1439 | wl_list_insert(&surface->geometry.transformation_list, |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1440 | &shsurf->fullscreen.transform.link); |
Kristian Høgsberg | 240dfeb | 2012-07-12 12:32:31 -0400 | [diff] [blame] | 1441 | x = output->x + (output->current->width - surface->geometry.width * scale) / 2; |
| 1442 | y = output->y + (output->current->height - surface->geometry.height * scale) / 2; |
| 1443 | weston_surface_set_position(surface, x, y); |
| 1444 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1445 | break; |
| 1446 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1447 | if (shell_surface_is_top_fullscreen(shsurf)) { |
| 1448 | struct weston_mode mode = {0, |
| 1449 | surface->geometry.width, |
| 1450 | surface->geometry.height, |
| 1451 | shsurf->fullscreen.framerate}; |
| 1452 | |
| 1453 | if (weston_output_switch_mode(output, &mode) == 0) { |
| 1454 | weston_surface_configure(shsurf->fullscreen.black_surface, |
| 1455 | output->x, output->y, |
| 1456 | output->current->width, |
| 1457 | output->current->height); |
| 1458 | weston_surface_set_position(surface, output->x, output->y); |
| 1459 | break; |
| 1460 | } |
| 1461 | } |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1462 | break; |
| 1463 | case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL: |
| 1464 | break; |
| 1465 | default: |
| 1466 | break; |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | /* make the fullscreen and black surface at the top */ |
| 1471 | static void |
| 1472 | shell_stack_fullscreen(struct shell_surface *shsurf) |
| 1473 | { |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1474 | struct weston_output *output = shsurf->fullscreen_output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1475 | struct weston_surface *surface = shsurf->surface; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1476 | struct desktop_shell *shell = shell_surface_get_shell(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1477 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1478 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1479 | wl_list_insert(&shell->fullscreen_layer.surface_list, |
| 1480 | &surface->layer_link); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1481 | weston_surface_damage(surface); |
| 1482 | |
| 1483 | if (!shsurf->fullscreen.black_surface) |
| 1484 | shsurf->fullscreen.black_surface = |
| 1485 | create_black_surface(surface->compositor, |
| 1486 | surface, |
| 1487 | output->x, output->y, |
| 1488 | output->current->width, |
| 1489 | output->current->height); |
| 1490 | |
| 1491 | wl_list_remove(&shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1492 | wl_list_insert(&surface->layer_link, |
| 1493 | &shsurf->fullscreen.black_surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1494 | weston_surface_damage(shsurf->fullscreen.black_surface); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | static void |
| 1498 | shell_map_fullscreen(struct shell_surface *shsurf) |
| 1499 | { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1500 | shell_stack_fullscreen(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1501 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1502 | } |
| 1503 | |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1504 | static void |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1505 | shell_surface_set_fullscreen(struct wl_client *client, |
Kristian Høgsberg | f856fd2 | 2012-02-16 15:58:14 -0500 | [diff] [blame] | 1506 | struct wl_resource *resource, |
| 1507 | uint32_t method, |
| 1508 | uint32_t framerate, |
| 1509 | struct wl_resource *output_resource) |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1510 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1511 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1512 | struct weston_surface *es = shsurf->surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1513 | |
| 1514 | if (output_resource) |
| 1515 | shsurf->output = output_resource->data; |
Kristian Høgsberg | 94de680 | 2012-07-18 09:54:04 -0400 | [diff] [blame] | 1516 | else if (es->output) |
| 1517 | shsurf->output = es->output; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1518 | else |
| 1519 | shsurf->output = get_default_output(es->compositor); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1520 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1521 | shsurf->fullscreen_output = shsurf->output; |
| 1522 | shsurf->fullscreen.type = method; |
| 1523 | shsurf->fullscreen.framerate = framerate; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1524 | shsurf->next_type = SHELL_SURFACE_FULLSCREEN; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1525 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1526 | shsurf->client->send_configure(shsurf->surface, 0, |
| 1527 | shsurf->output->current->width, |
| 1528 | shsurf->output->current->height); |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 1529 | } |
| 1530 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1531 | static void |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1532 | popup_grab_focus(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1533 | struct wl_surface *surface, |
| 1534 | wl_fixed_t x, |
| 1535 | wl_fixed_t y) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1536 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1537 | struct wl_pointer *pointer = grab->pointer; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1538 | struct shell_surface *priv = |
| 1539 | container_of(grab, struct shell_surface, popup.grab); |
| 1540 | struct wl_client *client = priv->surface->surface.resource.client; |
| 1541 | |
Pekka Paalanen | cb10843 | 2012-01-19 16:25:40 +0200 | [diff] [blame] | 1542 | if (surface && surface->resource.client == client) { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1543 | wl_pointer_set_focus(pointer, surface, x, y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1544 | grab->focus = surface; |
| 1545 | } else { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1546 | wl_pointer_set_focus(pointer, NULL, |
| 1547 | wl_fixed_from_int(0), |
| 1548 | wl_fixed_from_int(0)); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1549 | grab->focus = NULL; |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1554 | popup_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1555 | uint32_t time, wl_fixed_t sx, wl_fixed_t sy) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1556 | { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1557 | struct wl_resource *resource; |
| 1558 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1559 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1560 | if (resource) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1561 | wl_pointer_send_motion(resource, time, sx, sy); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1565 | popup_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1566 | uint32_t time, uint32_t button, uint32_t state_w) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1567 | { |
| 1568 | struct wl_resource *resource; |
| 1569 | struct shell_surface *shsurf = |
| 1570 | container_of(grab, struct shell_surface, popup.grab); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1571 | struct wl_display *display; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1572 | enum wl_pointer_button_state state = state_w; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1573 | uint32_t serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1574 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1575 | resource = grab->pointer->focus_resource; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1576 | if (resource) { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1577 | display = wl_client_get_display(resource->client); |
| 1578 | serial = wl_display_get_serial(display); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1579 | wl_pointer_send_button(resource, serial, time, button, state); |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1580 | } else if (state == WL_POINTER_BUTTON_STATE_RELEASED && |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1581 | (shsurf->popup.initial_up || |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1582 | time - shsurf->popup.seat->pointer->grab_time > 500)) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1583 | wl_shell_surface_send_popup_done(&shsurf->resource); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1584 | wl_pointer_end_grab(grab->pointer); |
| 1585 | shsurf->popup.grab.pointer = NULL; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1586 | } |
| 1587 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 1588 | if (state == WL_POINTER_BUTTON_STATE_RELEASED) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1589 | shsurf->popup.initial_up = 1; |
| 1590 | } |
| 1591 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 1592 | static const struct wl_pointer_grab_interface popup_grab_interface = { |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1593 | popup_grab_focus, |
| 1594 | popup_grab_motion, |
| 1595 | popup_grab_button, |
| 1596 | }; |
| 1597 | |
| 1598 | static void |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1599 | shell_map_popup(struct shell_surface *shsurf) |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1600 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1601 | struct wl_seat *seat = shsurf->popup.seat; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1602 | struct weston_surface *es = shsurf->surface; |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 1603 | struct weston_surface *parent = shsurf->parent; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1604 | |
| 1605 | es->output = parent->output; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1606 | shsurf->popup.grab.interface = &popup_grab_interface; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1607 | |
Pekka Paalanen | 938269a | 2012-02-07 14:19:01 +0200 | [diff] [blame] | 1608 | weston_surface_update_transform(parent); |
| 1609 | if (parent->transform.enabled) { |
| 1610 | shsurf->popup.parent_transform.matrix = |
| 1611 | parent->transform.matrix; |
| 1612 | } else { |
| 1613 | /* construct x, y translation matrix */ |
| 1614 | weston_matrix_init(&shsurf->popup.parent_transform.matrix); |
| 1615 | shsurf->popup.parent_transform.matrix.d[12] = |
| 1616 | parent->geometry.x; |
| 1617 | shsurf->popup.parent_transform.matrix.d[13] = |
| 1618 | parent->geometry.y; |
| 1619 | } |
| 1620 | wl_list_insert(es->geometry.transformation_list.prev, |
| 1621 | &shsurf->popup.parent_transform.link); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1622 | weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1623 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1624 | shsurf->popup.initial_up = 0; |
| 1625 | |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1626 | /* We don't require the grab to still be active, but if another |
| 1627 | * grab has started in the meantime, we end the popup now. */ |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1628 | if (seat->pointer->grab_serial == shsurf->popup.serial) { |
| 1629 | wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab); |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1630 | } else { |
| 1631 | wl_shell_surface_send_popup_done(&shsurf->resource); |
| 1632 | } |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | static void |
| 1636 | shell_surface_set_popup(struct wl_client *client, |
| 1637 | struct wl_resource *resource, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1638 | struct wl_resource *seat_resource, |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1639 | uint32_t serial, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1640 | struct wl_resource *parent_resource, |
| 1641 | int32_t x, int32_t y, uint32_t flags) |
| 1642 | { |
| 1643 | struct shell_surface *shsurf = resource->data; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1644 | |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1645 | shsurf->type = SHELL_SURFACE_POPUP; |
| 1646 | shsurf->parent = parent_resource->data; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1647 | shsurf->popup.seat = seat_resource->data; |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 1648 | shsurf->popup.serial = serial; |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1649 | shsurf->popup.x = x; |
| 1650 | shsurf->popup.y = y; |
| 1651 | } |
| 1652 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1653 | static const struct wl_shell_surface_interface shell_surface_implementation = { |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1654 | shell_surface_pong, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1655 | shell_surface_move, |
| 1656 | shell_surface_resize, |
| 1657 | shell_surface_set_toplevel, |
| 1658 | shell_surface_set_transient, |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1659 | shell_surface_set_fullscreen, |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 1660 | shell_surface_set_popup, |
Kristian Høgsberg | e7afd91 | 2012-05-02 09:47:44 -0400 | [diff] [blame] | 1661 | shell_surface_set_maximized, |
| 1662 | shell_surface_set_title, |
| 1663 | shell_surface_set_class |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1664 | }; |
| 1665 | |
| 1666 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1667 | destroy_shell_surface(struct shell_surface *shsurf) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1668 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1669 | if (shsurf->popup.grab.pointer) |
| 1670 | wl_pointer_end_grab(shsurf->popup.grab.pointer); |
Kristian Høgsberg | b3cca0a | 2012-01-04 22:19:14 -0500 | [diff] [blame] | 1671 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1672 | if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER && |
| 1673 | shell_surface_is_top_fullscreen(shsurf)) { |
| 1674 | weston_output_switch_mode(shsurf->fullscreen_output, |
| 1675 | shsurf->fullscreen_output->origin); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1676 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1677 | |
Alex Wu | aa08e2d | 2012-03-05 11:01:40 +0800 | [diff] [blame] | 1678 | if (shsurf->fullscreen.black_surface) |
| 1679 | weston_surface_destroy(shsurf->fullscreen.black_surface); |
| 1680 | |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1681 | /* As destroy_resource() use wl_list_for_each_safe(), |
| 1682 | * we can always remove the listener. |
| 1683 | */ |
| 1684 | wl_list_remove(&shsurf->surface_destroy_listener.link); |
| 1685 | shsurf->surface->configure = NULL; |
Scott Moreau | 9521d5e | 2012-04-19 13:06:17 -0600 | [diff] [blame] | 1686 | ping_timer_destroy(shsurf); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 1687 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1688 | wl_list_remove(&shsurf->link); |
| 1689 | free(shsurf); |
| 1690 | } |
| 1691 | |
| 1692 | static void |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1693 | shell_destroy_shell_surface(struct wl_resource *resource) |
| 1694 | { |
| 1695 | struct shell_surface *shsurf = resource->data; |
| 1696 | |
| 1697 | destroy_shell_surface(shsurf); |
| 1698 | } |
| 1699 | |
| 1700 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1701 | shell_handle_surface_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1702 | { |
| 1703 | struct shell_surface *shsurf = container_of(listener, |
| 1704 | struct shell_surface, |
| 1705 | surface_destroy_listener); |
| 1706 | |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1707 | if (shsurf->resource.client) { |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1708 | wl_resource_destroy(&shsurf->resource); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1709 | } else { |
| 1710 | wl_signal_emit(&shsurf->resource.destroy_signal, |
| 1711 | &shsurf->resource); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1712 | destroy_shell_surface(shsurf); |
Kristian Høgsberg | 633b145 | 2012-06-07 18:08:47 -0400 | [diff] [blame] | 1713 | } |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1714 | } |
| 1715 | |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 1716 | static void |
| 1717 | shell_surface_configure(struct weston_surface *, int32_t, int32_t); |
| 1718 | |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1719 | static struct shell_surface * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1720 | get_shell_surface(struct weston_surface *surface) |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1721 | { |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 1722 | if (surface->configure == shell_surface_configure) |
| 1723 | return surface->private; |
| 1724 | else |
| 1725 | return NULL; |
Pekka Paalanen | ec2b32f | 2011-11-28 15:12:34 +0200 | [diff] [blame] | 1726 | } |
| 1727 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1728 | static struct shell_surface * |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1729 | create_shell_surface(void *shell, struct weston_surface *surface, |
| 1730 | const struct weston_shell_client *client) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1731 | { |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1732 | struct shell_surface *shsurf; |
| 1733 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1734 | if (surface->configure) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1735 | weston_log("surface->configure already set\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1736 | return NULL; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1737 | } |
| 1738 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1739 | shsurf = calloc(1, sizeof *shsurf); |
| 1740 | if (!shsurf) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1741 | weston_log("no memory to allocate shell surface\n"); |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1742 | return NULL; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1743 | } |
| 1744 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1745 | surface->configure = shell_surface_configure; |
Kristian Høgsberg | d813445 | 2012-06-21 12:49:02 -0400 | [diff] [blame] | 1746 | surface->private = shsurf; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 1747 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1748 | shsurf->shell = (struct desktop_shell *) shell; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1749 | shsurf->unresponsive = 0; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1750 | shsurf->saved_position_valid = false; |
Alex Wu | 7bcb8bd | 2012-04-27 09:07:24 +0800 | [diff] [blame] | 1751 | shsurf->saved_rotation_valid = false; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1752 | shsurf->surface = surface; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1753 | shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT; |
| 1754 | shsurf->fullscreen.framerate = 0; |
| 1755 | shsurf->fullscreen.black_surface = NULL; |
Scott Moreau | ff1db4a | 2012-04-17 19:06:18 -0600 | [diff] [blame] | 1756 | shsurf->ping_timer = NULL; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 1757 | wl_list_init(&shsurf->fullscreen.transform.link); |
| 1758 | |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1759 | wl_signal_init(&shsurf->resource.destroy_signal); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1760 | shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; |
| 1761 | wl_signal_add(&surface->surface.resource.destroy_signal, |
| 1762 | &shsurf->surface_destroy_listener); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1763 | |
| 1764 | /* init link so its safe to always remove it in destroy_shell_surface */ |
| 1765 | wl_list_init(&shsurf->link); |
| 1766 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1767 | /* empty when not in use */ |
| 1768 | wl_list_init(&shsurf->rotation.transform.link); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 1769 | weston_matrix_init(&shsurf->rotation.rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 1770 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 1771 | wl_list_init(&shsurf->workspace_transform.link); |
| 1772 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1773 | shsurf->type = SHELL_SURFACE_NONE; |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 1774 | shsurf->next_type = SHELL_SURFACE_NONE; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1775 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1776 | shsurf->client = client; |
| 1777 | |
Kristian Høgsberg | 45ba869 | 2012-05-21 14:27:33 -0400 | [diff] [blame] | 1778 | return shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | static void |
| 1782 | shell_get_shell_surface(struct wl_client *client, |
| 1783 | struct wl_resource *resource, |
| 1784 | uint32_t id, |
| 1785 | struct wl_resource *surface_resource) |
| 1786 | { |
| 1787 | struct weston_surface *surface = surface_resource->data; |
| 1788 | struct desktop_shell *shell = resource->data; |
| 1789 | struct shell_surface *shsurf; |
| 1790 | |
| 1791 | if (get_shell_surface(surface)) { |
| 1792 | wl_resource_post_error(surface_resource, |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1793 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1794 | "desktop_shell::get_shell_surface already requested"); |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1795 | return; |
| 1796 | } |
| 1797 | |
Kristian Høgsberg | a61ca06 | 2012-05-22 16:05:52 -0400 | [diff] [blame] | 1798 | shsurf = create_shell_surface(shell, surface, &shell_client); |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1799 | if (!shsurf) { |
| 1800 | wl_resource_post_error(surface_resource, |
| 1801 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1802 | "surface->configure already set"); |
| 1803 | return; |
| 1804 | } |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1805 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1806 | shsurf->resource.destroy = shell_destroy_shell_surface; |
| 1807 | shsurf->resource.object.id = id; |
| 1808 | shsurf->resource.object.interface = &wl_shell_surface_interface; |
| 1809 | shsurf->resource.object.implementation = |
| 1810 | (void (**)(void)) &shell_surface_implementation; |
| 1811 | shsurf->resource.data = shsurf; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 1812 | |
Kristian Høgsberg | 9540ea6 | 2012-05-21 14:28:57 -0400 | [diff] [blame] | 1813 | wl_client_add_resource(client, &shsurf->resource); |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | static const struct wl_shell_interface shell_implementation = { |
Pekka Paalanen | 4622967 | 2011-11-29 15:49:31 +0200 | [diff] [blame] | 1817 | shell_get_shell_surface |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 1818 | }; |
| 1819 | |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 1820 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1821 | handle_screensaver_sigchld(struct weston_process *proc, int status) |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1822 | { |
| 1823 | proc->pid = 0; |
| 1824 | } |
| 1825 | |
| 1826 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1827 | launch_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1828 | { |
| 1829 | if (shell->screensaver.binding) |
| 1830 | return; |
| 1831 | |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1832 | if (!shell->screensaver.path) |
| 1833 | return; |
| 1834 | |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 1835 | if (shell->screensaver.process.pid != 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1836 | weston_log("old screensaver still running\n"); |
Kristian Høgsberg | 32bed57 | 2012-03-01 17:11:36 -0500 | [diff] [blame] | 1837 | return; |
| 1838 | } |
| 1839 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1840 | weston_client_launch(shell->compositor, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1841 | &shell->screensaver.process, |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 1842 | shell->screensaver.path, |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1843 | handle_screensaver_sigchld); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1847 | terminate_screensaver(struct desktop_shell *shell) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1848 | { |
Pekka Paalanen | 18027e5 | 2011-12-02 16:31:49 +0200 | [diff] [blame] | 1849 | if (shell->screensaver.process.pid == 0) |
| 1850 | return; |
| 1851 | |
| 1852 | kill(shell->screensaver.process.pid, SIGTERM); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1856 | configure_static_surface(struct weston_surface *es, struct weston_layer *layer) |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1857 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1858 | struct weston_surface *s, *next; |
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 | wl_list_for_each_safe(s, next, &layer->surface_list, layer_link) { |
| 1861 | if (s->output == es->output && s != es) { |
| 1862 | weston_surface_unmap(s); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1863 | s->configure = NULL; |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | weston_surface_configure(es, es->output->x, es->output->y, |
| 1868 | es->buffer->width, es->buffer->height); |
| 1869 | |
| 1870 | if (wl_list_empty(&es->layer_link)) { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1871 | wl_list_insert(&layer->surface_list, &es->layer_link); |
Kristian Høgsberg | c7cd626 | 2012-06-28 13:46:09 -0400 | [diff] [blame] | 1872 | weston_compositor_schedule_repaint(es->compositor); |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1877 | background_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 1878 | { |
| 1879 | struct desktop_shell *shell = es->private; |
| 1880 | |
| 1881 | configure_static_surface(es, &shell->background_layer); |
| 1882 | } |
| 1883 | |
| 1884 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1885 | desktop_shell_set_background(struct wl_client *client, |
| 1886 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1887 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1888 | struct wl_resource *surface_resource) |
| 1889 | { |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1890 | struct desktop_shell *shell = resource->data; |
| 1891 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1892 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1893 | if (surface->configure) { |
| 1894 | wl_resource_post_error(surface_resource, |
| 1895 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1896 | "surface role already assigned"); |
| 1897 | return; |
| 1898 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1899 | |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1900 | surface->configure = background_configure; |
| 1901 | surface->private = shell; |
| 1902 | surface->output = output_resource->data; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1903 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 1904 | surface_resource, |
Kristian Høgsberg | 962342c | 2012-06-26 16:29:50 -0400 | [diff] [blame] | 1905 | surface->output->current->width, |
| 1906 | surface->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1907 | } |
| 1908 | |
| 1909 | static void |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1910 | panel_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 1911 | { |
| 1912 | struct desktop_shell *shell = es->private; |
| 1913 | |
| 1914 | configure_static_surface(es, &shell->panel_layer); |
| 1915 | } |
| 1916 | |
| 1917 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1918 | desktop_shell_set_panel(struct wl_client *client, |
| 1919 | struct wl_resource *resource, |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1920 | struct wl_resource *output_resource, |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1921 | struct wl_resource *surface_resource) |
| 1922 | { |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1923 | struct desktop_shell *shell = resource->data; |
| 1924 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1925 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1926 | if (surface->configure) { |
| 1927 | wl_resource_post_error(surface_resource, |
| 1928 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 1929 | "surface role already assigned"); |
| 1930 | return; |
| 1931 | } |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 1932 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1933 | surface->configure = panel_configure; |
| 1934 | surface->private = shell; |
| 1935 | surface->output = output_resource->data; |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1936 | desktop_shell_send_configure(resource, 0, |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1937 | surface_resource, |
| 1938 | surface->output->current->width, |
| 1939 | surface->output->current->height); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 1940 | } |
| 1941 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1942 | static void |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 1943 | lock_surface_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
| 1944 | { |
| 1945 | struct desktop_shell *shell = surface->private; |
| 1946 | |
| 1947 | center_on_output(surface, get_default_output(shell->compositor)); |
| 1948 | |
| 1949 | if (!weston_surface_is_mapped(surface)) { |
| 1950 | wl_list_insert(&shell->lock_layer.surface_list, |
| 1951 | &surface->layer_link); |
| 1952 | weston_surface_assign_output(surface); |
| 1953 | weston_compositor_wake(shell->compositor); |
| 1954 | } |
| 1955 | } |
| 1956 | |
| 1957 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1958 | handle_lock_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1959 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1960 | struct desktop_shell *shell = |
| 1961 | container_of(listener, struct desktop_shell, lock_surface_listener); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1962 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1963 | weston_log("lock surface gone\n"); |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1964 | shell->lock_surface = NULL; |
| 1965 | } |
| 1966 | |
| 1967 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 1968 | desktop_shell_set_lock_surface(struct wl_client *client, |
| 1969 | struct wl_resource *resource, |
| 1970 | struct wl_resource *surface_resource) |
| 1971 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1972 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 1973 | struct weston_surface *surface = surface_resource->data; |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1974 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1975 | shell->prepare_event_sent = false; |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 1976 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1977 | if (!shell->locked) |
| 1978 | return; |
| 1979 | |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 1980 | shell->lock_surface = surface; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1981 | |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 1982 | shell->lock_surface_listener.notify = handle_lock_surface_destroy; |
| 1983 | wl_signal_add(&surface_resource->destroy_signal, |
| 1984 | &shell->lock_surface_listener); |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 1985 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 1986 | surface->configure = lock_surface_configure; |
| 1987 | surface->private = shell; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 1991 | resume_desktop(struct desktop_shell *shell) |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 1992 | { |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 1993 | struct weston_surface *surface; |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 1994 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1995 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 1996 | wl_list_for_each(surface, &shell->screensaver.surfaces, link) |
| 1997 | weston_surface_unmap(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 1998 | |
| 1999 | terminate_screensaver(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2000 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2001 | wl_list_remove(&shell->lock_layer.link); |
| 2002 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 2003 | &shell->fullscreen_layer.link); |
| 2004 | wl_list_insert(&shell->fullscreen_layer.link, |
| 2005 | &shell->panel_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2006 | wl_list_insert(&shell->panel_layer.link, &ws->layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2007 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2008 | restore_focus_state(shell, get_current_workspace(shell)); |
Jonas Ådahl | 0476974 | 2012-06-13 00:01:24 +0200 | [diff] [blame] | 2009 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2010 | shell->locked = false; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 2011 | shell->compositor->idle_time = shell->compositor->option_idle_time; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2012 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | fc6d91a | 2012-02-10 15:33:10 +0200 | [diff] [blame] | 2013 | weston_compositor_damage_all(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | static void |
| 2017 | desktop_shell_unlock(struct wl_client *client, |
| 2018 | struct wl_resource *resource) |
| 2019 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2020 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2021 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2022 | shell->prepare_event_sent = false; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2023 | |
| 2024 | if (shell->locked) |
| 2025 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2026 | } |
| 2027 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2028 | static void |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2029 | desktop_shell_set_grab_surface(struct wl_client *client, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2030 | struct wl_resource *resource, |
| 2031 | struct wl_resource *surface_resource) |
| 2032 | { |
| 2033 | struct desktop_shell *shell = resource->data; |
| 2034 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2035 | shell->grab_surface = surface_resource->data; |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2038 | static const struct desktop_shell_interface desktop_shell_implementation = { |
| 2039 | desktop_shell_set_background, |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2040 | desktop_shell_set_panel, |
| 2041 | desktop_shell_set_lock_surface, |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 2042 | desktop_shell_unlock, |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2043 | desktop_shell_set_grab_surface |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2044 | }; |
| 2045 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2046 | static enum shell_surface_type |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2047 | get_shell_surface_type(struct weston_surface *surface) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2048 | { |
| 2049 | struct shell_surface *shsurf; |
| 2050 | |
| 2051 | shsurf = get_shell_surface(surface); |
| 2052 | if (!shsurf) |
Pekka Paalanen | 9826223 | 2011-12-01 10:42:22 +0200 | [diff] [blame] | 2053 | return SHELL_SURFACE_NONE; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2054 | return shsurf->type; |
| 2055 | } |
| 2056 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2057 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2058 | 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] | 2059 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2060 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2061 | (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2062 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2063 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2064 | if (surface == NULL) |
| 2065 | return; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2066 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2067 | shsurf = get_shell_surface(surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2068 | if (shsurf == NULL || shsurf->type == SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2069 | return; |
| 2070 | |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 2071 | surface_move(shsurf, (struct weston_seat *) seat); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2075 | 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] | 2076 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2077 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2078 | (struct weston_surface *) seat->pointer->focus; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2079 | uint32_t edges = 0; |
| 2080 | int32_t x, y; |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2081 | struct shell_surface *shsurf; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2082 | |
Benjamin Franzke | d0f79ab | 2011-11-22 12:43:52 +0100 | [diff] [blame] | 2083 | if (surface == NULL) |
| 2084 | return; |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2085 | |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2086 | shsurf = get_shell_surface(surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2087 | if (!shsurf || shsurf->type == SHELL_SURFACE_FULLSCREEN) |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2088 | return; |
| 2089 | |
Pekka Paalanen | 5c97ae7 | 2012-01-30 16:19:47 +0200 | [diff] [blame] | 2090 | weston_surface_from_global(surface, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2091 | wl_fixed_to_int(seat->pointer->grab_x), |
| 2092 | wl_fixed_to_int(seat->pointer->grab_y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2093 | &x, &y); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2094 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2095 | if (x < surface->geometry.width / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2096 | edges |= WL_SHELL_SURFACE_RESIZE_LEFT; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2097 | else if (x < 2 * surface->geometry.width / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2098 | edges |= 0; |
| 2099 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2100 | edges |= WL_SHELL_SURFACE_RESIZE_RIGHT; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2101 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2102 | if (y < surface->geometry.height / 3) |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2103 | edges |= WL_SHELL_SURFACE_RESIZE_TOP; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2104 | else if (y < 2 * surface->geometry.height / 3) |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2105 | edges |= 0; |
| 2106 | else |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2107 | edges |= WL_SHELL_SURFACE_RESIZE_BOTTOM; |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2108 | |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 2109 | surface_resize(shsurf, (struct weston_seat *) seat, edges); |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2113 | 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] | 2114 | wl_fixed_t value, void *data) |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2115 | { |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2116 | float step = 0.05; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2117 | struct shell_surface *shsurf; |
| 2118 | struct weston_surface *surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2119 | (struct weston_surface *) seat->pointer->focus; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2120 | |
| 2121 | if (surface == NULL) |
| 2122 | return; |
| 2123 | |
| 2124 | shsurf = get_shell_surface(surface); |
| 2125 | if (!shsurf) |
| 2126 | return; |
| 2127 | |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2128 | surface->alpha += wl_fixed_to_double(value) * step; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2129 | |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2130 | if (surface->alpha > 1.0) |
| 2131 | surface->alpha = 1.0; |
Scott Moreau | a3aa9c9 | 2012-03-22 11:01:03 -0600 | [diff] [blame] | 2132 | if (surface->alpha < step) |
| 2133 | surface->alpha = step; |
| 2134 | |
| 2135 | surface->geometry.dirty = 1; |
| 2136 | weston_surface_damage(surface); |
| 2137 | } |
| 2138 | |
| 2139 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2140 | 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] | 2141 | wl_fixed_t value) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2142 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2143 | struct weston_seat *ws = (struct weston_seat *) seat; |
| 2144 | struct weston_compositor *compositor = ws->compositor; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2145 | struct weston_output *output; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2146 | float increment; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2147 | |
| 2148 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2149 | if (pixman_region32_contains_point(&output->region, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2150 | wl_fixed_to_double(seat->pointer->x), |
| 2151 | wl_fixed_to_double(seat->pointer->y), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2152 | NULL)) { |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2153 | if (key == KEY_PAGEUP) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2154 | increment = output->zoom.increment; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2155 | else if (key == KEY_PAGEDOWN) |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2156 | increment = -output->zoom.increment; |
| 2157 | else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) |
Daniel Stone | 0c1e46e | 2012-05-30 16:31:59 +0100 | [diff] [blame] | 2158 | increment = output->zoom.increment * |
| 2159 | wl_fixed_to_double(value); |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2160 | else |
| 2161 | increment = 0; |
| 2162 | |
Kristian Høgsberg | 9b68af0 | 2012-05-22 12:55:18 -0400 | [diff] [blame] | 2163 | output->zoom.level += increment; |
Scott Moreau | c6d7f60 | 2012-02-23 22:28:37 -0700 | [diff] [blame] | 2164 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2165 | if (output->zoom.level < 0.0) |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2166 | output->zoom.level = 0.0; |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2167 | else if (output->zoom.level > output->zoom.max_level) |
| 2168 | output->zoom.level = output->zoom.max_level; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame^] | 2169 | else { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2170 | output->zoom.active = 1; |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame^] | 2171 | output->disable_planes++; |
| 2172 | } |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2173 | |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2174 | output->zoom.spring_z.target = output->zoom.level; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2175 | |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 2176 | weston_output_update_zoom(output, output->zoom.type); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2181 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2182 | 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] | 2183 | wl_fixed_t value, void *data) |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2184 | { |
| 2185 | do_zoom(seat, time, 0, axis, value); |
| 2186 | } |
| 2187 | |
| 2188 | static void |
| 2189 | zoom_key_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2190 | void *data) |
| 2191 | { |
| 2192 | do_zoom(seat, time, key, 0, 0); |
| 2193 | } |
| 2194 | |
| 2195 | static void |
| 2196 | terminate_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 2197 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2198 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2199 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2200 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2201 | wl_display_terminate(compositor->wl_display); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2205 | rotate_grab_motion(struct wl_pointer_grab *grab, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 2206 | uint32_t time, wl_fixed_t x, wl_fixed_t y) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2207 | { |
| 2208 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2209 | container_of(grab, struct rotate_grab, base.grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2210 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2211 | struct shell_surface *shsurf = rotate->base.shsurf; |
| 2212 | struct weston_surface *surface; |
| 2213 | GLfloat cx, cy, dx, dy, cposx, cposy, dposx, dposy, r; |
| 2214 | |
| 2215 | if (!shsurf) |
| 2216 | return; |
| 2217 | |
| 2218 | surface = shsurf->surface; |
| 2219 | |
| 2220 | cx = 0.5f * surface->geometry.width; |
| 2221 | cy = 0.5f * surface->geometry.height; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2222 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2223 | dx = wl_fixed_to_double(pointer->x) - rotate->center.x; |
| 2224 | dy = wl_fixed_to_double(pointer->y) - rotate->center.y; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2225 | r = sqrtf(dx * dx + dy * dy); |
| 2226 | |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2227 | wl_list_remove(&shsurf->rotation.transform.link); |
| 2228 | shsurf->surface->geometry.dirty = 1; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2229 | |
| 2230 | if (r > 20.0f) { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2231 | struct weston_matrix *matrix = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2232 | &shsurf->rotation.transform.matrix; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2233 | |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2234 | weston_matrix_init(&rotate->rotation); |
| 2235 | rotate->rotation.d[0] = dx / r; |
| 2236 | rotate->rotation.d[4] = -dy / r; |
| 2237 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 2238 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2239 | |
| 2240 | weston_matrix_init(matrix); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2241 | weston_matrix_translate(matrix, -cx, -cy, 0.0f); |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2242 | weston_matrix_multiply(matrix, &shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2243 | weston_matrix_multiply(matrix, &rotate->rotation); |
Pekka Paalanen | 7b3bd3d | 2012-01-30 14:16:34 +0200 | [diff] [blame] | 2244 | weston_matrix_translate(matrix, cx, cy, 0.0f); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2245 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 2246 | wl_list_insert( |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2247 | &shsurf->surface->geometry.transformation_list, |
| 2248 | &shsurf->rotation.transform.link); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2249 | } else { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2250 | wl_list_init(&shsurf->rotation.transform.link); |
| 2251 | weston_matrix_init(&shsurf->rotation.rotation); |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2252 | weston_matrix_init(&rotate->rotation); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2253 | } |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2254 | |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2255 | /* We need to adjust the position of the surface |
| 2256 | * in case it was resized in a rotated state before */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2257 | cposx = surface->geometry.x + cx; |
| 2258 | cposy = surface->geometry.y + cy; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2259 | dposx = rotate->center.x - cposx; |
| 2260 | dposy = rotate->center.y - cposy; |
| 2261 | if (dposx != 0.0f || dposy != 0.0f) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2262 | weston_surface_set_position(surface, |
| 2263 | surface->geometry.x + dposx, |
| 2264 | surface->geometry.y + dposy); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2265 | } |
| 2266 | |
Pekka Paalanen | b45ac5e | 2012-02-09 15:58:44 +0200 | [diff] [blame] | 2267 | /* Repaint implies weston_surface_update_transform(), which |
| 2268 | * lazily applies the damage due to rotation update. |
| 2269 | */ |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2270 | weston_compositor_schedule_repaint(shsurf->surface->compositor); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | static void |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2274 | rotate_grab_button(struct wl_pointer_grab *grab, |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2275 | uint32_t time, uint32_t button, uint32_t state_w) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2276 | { |
| 2277 | struct rotate_grab *rotate = |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2278 | container_of(grab, struct rotate_grab, base.grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2279 | struct wl_pointer *pointer = grab->pointer; |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2280 | struct shell_surface *shsurf = rotate->base.shsurf; |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2281 | enum wl_pointer_button_state state = state_w; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2282 | |
Daniel Stone | 4dbadb1 | 2012-05-30 16:31:51 +0100 | [diff] [blame] | 2283 | if (pointer->button_count == 0 && |
| 2284 | state == WL_POINTER_BUTTON_STATE_RELEASED) { |
Ander Conselvan de Oliveira | fe0444a | 2012-04-04 17:48:05 +0300 | [diff] [blame] | 2285 | if (shsurf) |
| 2286 | weston_matrix_multiply(&shsurf->rotation.rotation, |
| 2287 | &rotate->rotation); |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2288 | shell_grab_end(&rotate->base); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2289 | free(rotate); |
| 2290 | } |
| 2291 | } |
| 2292 | |
Scott Moreau | 447013d | 2012-02-18 05:05:29 -0700 | [diff] [blame] | 2293 | static const struct wl_pointer_grab_interface rotate_grab_interface = { |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2294 | noop_grab_focus, |
| 2295 | rotate_grab_motion, |
| 2296 | rotate_grab_button, |
| 2297 | }; |
| 2298 | |
| 2299 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2300 | rotate_binding(struct wl_seat *seat, uint32_t time, uint32_t button, |
Daniel Stone | e5a0120 | 2012-05-04 11:21:57 +0100 | [diff] [blame] | 2301 | void *data) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2302 | { |
| 2303 | struct weston_surface *base_surface = |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2304 | (struct weston_surface *) seat->pointer->focus; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2305 | struct shell_surface *surface; |
| 2306 | struct rotate_grab *rotate; |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2307 | GLfloat dx, dy; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2308 | GLfloat r; |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2309 | |
| 2310 | if (base_surface == NULL) |
| 2311 | return; |
| 2312 | |
| 2313 | surface = get_shell_surface(base_surface); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2314 | if (!surface || surface->type == SHELL_SURFACE_FULLSCREEN) |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2315 | return; |
| 2316 | |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2317 | rotate = malloc(sizeof *rotate); |
| 2318 | if (!rotate) |
| 2319 | return; |
| 2320 | |
Kristian Høgsberg | b2af93e | 2012-06-07 20:10:23 -0400 | [diff] [blame] | 2321 | weston_surface_to_global_float(surface->surface, |
| 2322 | surface->surface->geometry.width / 2, |
| 2323 | surface->surface->geometry.height / 2, |
| 2324 | &rotate->center.x, &rotate->center.y); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2325 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2326 | dx = wl_fixed_to_double(seat->pointer->x) - rotate->center.x; |
| 2327 | dy = wl_fixed_to_double(seat->pointer->y) - rotate->center.y; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2328 | r = sqrtf(dx * dx + dy * dy); |
| 2329 | if (r > 20.0f) { |
| 2330 | struct weston_matrix inverse; |
| 2331 | |
| 2332 | weston_matrix_init(&inverse); |
| 2333 | inverse.d[0] = dx / r; |
| 2334 | inverse.d[4] = dy / r; |
| 2335 | inverse.d[1] = -inverse.d[4]; |
| 2336 | inverse.d[5] = inverse.d[0]; |
| 2337 | weston_matrix_multiply(&surface->rotation.rotation, &inverse); |
Rafal Mielniczuk | 2d7ab82 | 2012-03-22 22:22:04 +0100 | [diff] [blame] | 2338 | |
| 2339 | weston_matrix_init(&rotate->rotation); |
| 2340 | rotate->rotation.d[0] = dx / r; |
| 2341 | rotate->rotation.d[4] = -dy / r; |
| 2342 | rotate->rotation.d[1] = -rotate->rotation.d[4]; |
| 2343 | rotate->rotation.d[5] = rotate->rotation.d[0]; |
Kristian Høgsberg | 765e27b | 2012-01-27 13:36:13 -0500 | [diff] [blame] | 2344 | } else { |
| 2345 | weston_matrix_init(&surface->rotation.rotation); |
| 2346 | weston_matrix_init(&rotate->rotation); |
| 2347 | } |
| 2348 | |
Ander Conselvan de Oliveira | b9d2a0f | 2012-06-28 18:08:05 +0300 | [diff] [blame] | 2349 | shell_grab_start(&rotate->base, &rotate_grab_interface, surface, |
| 2350 | seat->pointer, DESKTOP_SHELL_CURSOR_ARROW); |
Pekka Paalanen | 460099f | 2012-01-20 16:48:25 +0200 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | static void |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2354 | lower_fullscreen_layer(struct desktop_shell *shell) |
| 2355 | { |
| 2356 | struct workspace *ws; |
| 2357 | struct weston_surface *surface, *prev; |
| 2358 | |
| 2359 | ws = get_current_workspace(shell); |
| 2360 | wl_list_for_each_reverse_safe(surface, prev, |
| 2361 | &shell->fullscreen_layer.surface_list, |
| 2362 | layer_link) |
| 2363 | weston_surface_restack(surface, &ws->layer.surface_list); |
| 2364 | } |
| 2365 | |
| 2366 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2367 | activate(struct desktop_shell *shell, struct weston_surface *es, |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2368 | struct weston_seat *seat) |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2369 | { |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2370 | struct workspace *ws = get_current_workspace(shell); |
| 2371 | struct focus_state *state; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2372 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2373 | weston_surface_activate(es, seat); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2374 | |
Kristian Høgsberg | 2f5faff | 2012-07-31 16:36:34 -0400 | [diff] [blame] | 2375 | wl_list_for_each(state, &ws->focus_list, link) |
| 2376 | if (state->seat == seat) |
| 2377 | break; |
| 2378 | |
| 2379 | if (&state->link == &ws->focus_list) { |
| 2380 | state = focus_state_create(seat, ws); |
| 2381 | if (state == NULL) |
| 2382 | return; |
| 2383 | } |
| 2384 | |
| 2385 | state->keyboard_focus = es; |
| 2386 | wl_list_remove(&state->surface_destroy_listener.link); |
| 2387 | wl_signal_add(&es->surface.resource.destroy_signal, |
| 2388 | &state->surface_destroy_listener); |
| 2389 | |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2390 | switch (get_shell_surface_type(es)) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2391 | case SHELL_SURFACE_FULLSCREEN: |
| 2392 | /* should on top of panels */ |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2393 | shell_stack_fullscreen(get_shell_surface(es)); |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2394 | shell_configure_fullscreen(get_shell_surface(es)); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2395 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2396 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2397 | ws = get_current_workspace(shell); |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2398 | lower_fullscreen_layer(shell); |
| 2399 | weston_surface_restack(es, &ws->layer.surface_list); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2400 | break; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2404 | /* no-op func for checking black surface */ |
| 2405 | static void |
| 2406 | black_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2407 | { |
| 2408 | } |
| 2409 | |
| 2410 | static bool |
| 2411 | is_black_surface (struct weston_surface *es, struct weston_surface **fs_surface) |
| 2412 | { |
| 2413 | if (es->configure == black_surface_configure) { |
| 2414 | if (fs_surface) |
| 2415 | *fs_surface = (struct weston_surface *)es->private; |
| 2416 | return true; |
| 2417 | } |
| 2418 | return false; |
| 2419 | } |
| 2420 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2421 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2422 | 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] | 2423 | void *data) |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2424 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2425 | struct weston_seat *ws = (struct weston_seat *) seat; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2426 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2427 | struct weston_surface *focus; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2428 | struct weston_surface *upper; |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2429 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2430 | focus = (struct weston_surface *) seat->pointer->focus; |
Alex Wu | 9c35e6b | 2012-03-05 14:13:13 +0800 | [diff] [blame] | 2431 | if (!focus) |
| 2432 | return; |
| 2433 | |
Alex Wu | 2185843 | 2012-04-01 20:13:08 +0800 | [diff] [blame] | 2434 | if (is_black_surface(focus, &upper)) |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2435 | focus = upper; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2436 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2437 | if (get_shell_surface_type(focus) == SHELL_SURFACE_NONE) |
| 2438 | return; |
Kristian Høgsberg | 85b2e4b | 2012-06-21 16:49:42 -0400 | [diff] [blame] | 2439 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2440 | if (seat->pointer->grab == &seat->pointer->default_grab) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2441 | activate(shell, focus, ws); |
Kristian Høgsberg | e1a850e | 2011-12-19 15:18:05 -0500 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2445 | lock(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2446 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2447 | struct desktop_shell *shell = |
| 2448 | container_of(listener, struct desktop_shell, lock_listener); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2449 | struct weston_output *output; |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2450 | struct workspace *ws = get_current_workspace(shell); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2451 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2452 | if (shell->locked) { |
| 2453 | wl_list_for_each(output, &shell->compositor->output_list, link) |
| 2454 | /* TODO: find a way to jump to other DPMS levels */ |
| 2455 | if (output->set_dpms) |
| 2456 | output->set_dpms(output, WESTON_DPMS_STANDBY); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2457 | return; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2458 | } |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2459 | |
| 2460 | shell->locked = true; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2461 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2462 | /* Hide all surfaces by removing the fullscreen, panel and |
| 2463 | * toplevel layers. This way nothing else can show or receive |
| 2464 | * input events while we are locked. */ |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2465 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2466 | wl_list_remove(&shell->panel_layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2467 | wl_list_remove(&shell->fullscreen_layer.link); |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 2468 | wl_list_remove(&ws->layer.link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2469 | wl_list_insert(&shell->compositor->cursor_layer.link, |
| 2470 | &shell->lock_layer.link); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2471 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2472 | launch_screensaver(shell); |
| 2473 | |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2474 | /* TODO: disable bindings that should not work while locked. */ |
| 2475 | |
| 2476 | /* All this must be undone in resume_desktop(). */ |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2480 | unlock(struct wl_listener *listener, void *data) |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2481 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2482 | struct desktop_shell *shell = |
| 2483 | container_of(listener, struct desktop_shell, unlock_listener); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2484 | |
Pekka Paalanen | d81c216 | 2011-11-16 13:47:34 +0200 | [diff] [blame] | 2485 | if (!shell->locked || shell->lock_surface) { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2486 | weston_compositor_wake(shell->compositor); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2487 | return; |
| 2488 | } |
| 2489 | |
| 2490 | /* If desktop-shell client has gone away, unlock immediately. */ |
| 2491 | if (!shell->child.desktop_shell) { |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2492 | resume_desktop(shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2493 | return; |
| 2494 | } |
| 2495 | |
| 2496 | if (shell->prepare_event_sent) |
| 2497 | return; |
| 2498 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2499 | desktop_shell_send_prepare_lock_surface(shell->child.desktop_shell); |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2500 | shell->prepare_event_sent = true; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2504 | show_input_panels(struct wl_listener *listener, void *data) |
| 2505 | { |
| 2506 | struct desktop_shell *shell = |
| 2507 | container_of(listener, struct desktop_shell, show_input_panel_listener); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2508 | struct weston_surface *surface, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2509 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2510 | wl_list_for_each_safe(surface, next, |
| 2511 | &shell->input_panel.surfaces, layer_link) { |
| 2512 | wl_list_remove(&surface->layer_link); |
| 2513 | wl_list_insert(&shell->panel_layer.surface_list, |
| 2514 | &surface->layer_link); |
| 2515 | weston_surface_assign_output(surface); |
| 2516 | weston_surface_damage(surface); |
| 2517 | weston_slide_run(surface, |
| 2518 | surface->geometry.height, 0, NULL, NULL); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | static void |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2523 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy); |
| 2524 | |
| 2525 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2526 | hide_input_panels(struct wl_listener *listener, void *data) |
| 2527 | { |
| 2528 | struct desktop_shell *shell = |
| 2529 | container_of(listener, struct desktop_shell, hide_input_panel_listener); |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2530 | struct weston_surface *surface, *next; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2531 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2532 | wl_list_for_each_safe(surface, next, |
| 2533 | &shell->panel_layer.surface_list, layer_link) |
| 2534 | if (surface->configure == input_panel_configure) { |
| 2535 | weston_surface_unmap(surface); |
| 2536 | wl_list_insert(&shell->input_panel.surfaces, |
| 2537 | &surface->layer_link); |
| 2538 | } |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2542 | center_on_output(struct weston_surface *surface, struct weston_output *output) |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2543 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2544 | struct weston_mode *mode = output->current; |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2545 | GLfloat x = (mode->width - surface->buffer->width) / 2; |
| 2546 | GLfloat y = (mode->height - surface->buffer->height) / 2; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2547 | |
Kristian Høgsberg | 730c94d | 2012-06-26 21:44:35 -0400 | [diff] [blame] | 2548 | weston_surface_configure(surface, output->x + x, output->y + y, |
| 2549 | surface->buffer->width, |
| 2550 | surface->buffer->height); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2554 | map(struct desktop_shell *shell, struct weston_surface *surface, |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 2555 | 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] | 2556 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2557 | struct weston_compositor *compositor = shell->compositor; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2558 | struct shell_surface *shsurf = get_shell_surface(surface); |
| 2559 | enum shell_surface_type surface_type = shsurf->type; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 2560 | struct weston_surface *parent; |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 2561 | struct weston_seat *seat; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2562 | struct workspace *ws; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2563 | int panel_height = 0; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2564 | |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2565 | surface->geometry.width = width; |
| 2566 | surface->geometry.height = height; |
| 2567 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2568 | |
| 2569 | /* initial positioning, see also configure() */ |
| 2570 | switch (surface_type) { |
| 2571 | case SHELL_SURFACE_TOPLEVEL: |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 2572 | weston_surface_set_position(surface, 10 + random() % 400, |
| 2573 | 10 + random() % 400); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2574 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2575 | case SHELL_SURFACE_FULLSCREEN: |
Kristian Høgsberg | e4d3a2b | 2012-07-09 21:43:22 -0400 | [diff] [blame] | 2576 | center_on_output(surface, shsurf->fullscreen_output); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2577 | shell_map_fullscreen(shsurf); |
| 2578 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2579 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2580 | /* use surface configure to set the geometry */ |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2581 | panel_height = get_output_panel_height(shell,surface->output); |
Rob Bradford | 31b6862 | 2012-07-02 19:00:19 +0100 | [diff] [blame] | 2582 | weston_surface_set_position(surface, shsurf->output->x, |
| 2583 | shsurf->output->y + panel_height); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2584 | break; |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 2585 | case SHELL_SURFACE_POPUP: |
Kristian Høgsberg | 3730f36 | 2012-04-13 12:40:07 -0400 | [diff] [blame] | 2586 | shell_map_popup(shsurf); |
Ander Conselvan de Oliveira | e9e0515 | 2012-02-15 17:02:56 +0200 | [diff] [blame] | 2587 | case SHELL_SURFACE_NONE: |
| 2588 | weston_surface_set_position(surface, |
| 2589 | surface->geometry.x + sx, |
| 2590 | surface->geometry.y + sy); |
Tiago Vignatti | 0f99701 | 2012-02-10 16:17:23 +0200 | [diff] [blame] | 2591 | break; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2592 | default: |
| 2593 | ; |
| 2594 | } |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2595 | |
Pekka Paalanen | d3dd6e1 | 2011-11-16 13:47:33 +0200 | [diff] [blame] | 2596 | /* surface stacking order, see also activate() */ |
Pekka Paalanen | 92a0dc4 | 2011-11-28 15:34:13 +0200 | [diff] [blame] | 2597 | switch (surface_type) { |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 2598 | case SHELL_SURFACE_POPUP: |
| 2599 | case SHELL_SURFACE_TRANSIENT: |
Kristian Høgsberg | 8150b19 | 2012-06-27 10:22:58 -0400 | [diff] [blame] | 2600 | parent = shsurf->parent; |
Kristian Høgsberg | 60c4954 | 2012-03-05 20:51:34 -0500 | [diff] [blame] | 2601 | wl_list_insert(parent->layer_link.prev, &surface->layer_link); |
| 2602 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2603 | case SHELL_SURFACE_FULLSCREEN: |
Ander Conselvan de Oliveira | a1ff53b | 2012-02-15 17:02:54 +0200 | [diff] [blame] | 2604 | case SHELL_SURFACE_NONE: |
| 2605 | break; |
Pekka Paalanen | 57da4a8 | 2011-11-23 16:42:16 +0200 | [diff] [blame] | 2606 | default: |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2607 | ws = get_current_workspace(shell); |
| 2608 | wl_list_insert(&ws->layer.surface_list, &surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2609 | break; |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 2610 | } |
| 2611 | |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 2612 | if (surface_type != SHELL_SURFACE_NONE) { |
| 2613 | weston_surface_assign_output(surface); |
Ander Conselvan de Oliveira | de56c31 | 2012-03-05 15:39:23 +0200 | [diff] [blame] | 2614 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
| 2615 | surface->output = shsurf->output; |
| 2616 | } |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 2617 | |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2618 | switch (surface_type) { |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2619 | case SHELL_SURFACE_TRANSIENT: |
Tiago Vignatti | 99aeb1e | 2012-05-23 22:06:26 +0300 | [diff] [blame] | 2620 | if (shsurf->transient.flags == |
| 2621 | WL_SHELL_SURFACE_TRANSIENT_INACTIVE) |
| 2622 | break; |
| 2623 | case SHELL_SURFACE_TOPLEVEL: |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2624 | case SHELL_SURFACE_FULLSCREEN: |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2625 | case SHELL_SURFACE_MAXIMIZED: |
Daniel Stone | b210468 | 2012-05-30 16:31:56 +0100 | [diff] [blame] | 2626 | if (!shell->locked) { |
| 2627 | wl_list_for_each(seat, &compositor->seat_list, link) |
| 2628 | activate(shell, surface, seat); |
| 2629 | } |
Juan Zhao | 7bb92f0 | 2011-12-15 11:31:51 -0500 | [diff] [blame] | 2630 | break; |
| 2631 | default: |
| 2632 | break; |
| 2633 | } |
| 2634 | |
Kristian Høgsberg | 2f88a40 | 2011-12-04 15:32:59 -0500 | [diff] [blame] | 2635 | if (surface_type == SHELL_SURFACE_TOPLEVEL) |
Juan Zhao | e10d279 | 2012-04-25 19:09:52 +0800 | [diff] [blame] | 2636 | { |
| 2637 | switch (shell->win_animation_type) { |
| 2638 | case ANIMATION_FADE: |
| 2639 | weston_fade_run(surface, NULL, NULL); |
| 2640 | break; |
| 2641 | case ANIMATION_ZOOM: |
| 2642 | weston_zoom_run(surface, 0.8, 1.0, NULL, NULL); |
| 2643 | break; |
| 2644 | default: |
| 2645 | break; |
| 2646 | } |
| 2647 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | static void |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2651 | configure(struct desktop_shell *shell, struct weston_surface *surface, |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 2652 | GLfloat x, GLfloat y, int32_t width, int32_t height) |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2653 | { |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2654 | enum shell_surface_type surface_type = SHELL_SURFACE_NONE; |
| 2655 | struct shell_surface *shsurf; |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2656 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2657 | shsurf = get_shell_surface(surface); |
| 2658 | if (shsurf) |
| 2659 | surface_type = shsurf->type; |
| 2660 | |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2661 | surface->geometry.x = x; |
| 2662 | surface->geometry.y = y; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 2663 | surface->geometry.width = width; |
| 2664 | surface->geometry.height = height; |
| 2665 | surface->geometry.dirty = 1; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2666 | |
| 2667 | switch (surface_type) { |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2668 | case SHELL_SURFACE_FULLSCREEN: |
Alex Wu | bd3354b | 2012-04-17 17:20:49 +0800 | [diff] [blame] | 2669 | shell_stack_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2670 | shell_configure_fullscreen(shsurf); |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2671 | break; |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2672 | case SHELL_SURFACE_MAXIMIZED: |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2673 | /* setting x, y and using configure to change that geometry */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2674 | surface->geometry.x = surface->output->x; |
| 2675 | surface->geometry.y = surface->output->y + |
| 2676 | get_output_panel_height(shell,surface->output); |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2677 | break; |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2678 | case SHELL_SURFACE_TOPLEVEL: |
| 2679 | break; |
Kristian Høgsberg | d2abb83 | 2011-11-23 10:52:40 -0500 | [diff] [blame] | 2680 | default: |
| 2681 | break; |
Kristian Høgsberg | 7a5c979 | 2011-06-18 06:12:54 -0400 | [diff] [blame] | 2682 | } |
Kristian Høgsberg | 32e24cc | 2011-11-09 12:07:35 -0500 | [diff] [blame] | 2683 | |
Alex Wu | 4539b08 | 2012-03-01 12:57:46 +0800 | [diff] [blame] | 2684 | /* XXX: would a fullscreen surface need the same handling? */ |
Kristian Høgsberg | 6a8b553 | 2012-02-16 23:43:59 -0500 | [diff] [blame] | 2685 | if (surface->output) { |
Pekka Paalanen | f07cb5d | 2012-02-10 13:34:36 +0200 | [diff] [blame] | 2686 | weston_surface_assign_output(surface); |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2687 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 2688 | if (surface_type == SHELL_SURFACE_MAXIMIZED) |
Juan Zhao | 96879df | 2012-02-07 08:45:41 +0800 | [diff] [blame] | 2689 | surface->output = shsurf->output; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2690 | } |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 2691 | } |
| 2692 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2693 | static void |
| 2694 | shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) |
| 2695 | { |
Ander Conselvan de Oliveira | 7fb9f95 | 2012-03-27 17:36:42 +0300 | [diff] [blame] | 2696 | struct shell_surface *shsurf = get_shell_surface(es); |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2697 | struct desktop_shell *shell = shsurf->shell; |
Tiago Vignatti | 70e5c9c | 2012-05-07 15:23:07 +0300 | [diff] [blame] | 2698 | int type_changed = 0; |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2699 | |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2700 | if (shsurf->next_type != SHELL_SURFACE_NONE && |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 2701 | shsurf->type != shsurf->next_type) { |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2702 | set_surface_type(shsurf); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 2703 | type_changed = 1; |
| 2704 | } |
Kristian Høgsberg | 7f366e7 | 2012-04-27 17:20:01 -0400 | [diff] [blame] | 2705 | |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2706 | if (!weston_surface_is_mapped(es)) { |
| 2707 | map(shell, es, es->buffer->width, es->buffer->height, sx, sy); |
Kristian Høgsberg | f7e23d5 | 2012-04-27 17:51:59 -0400 | [diff] [blame] | 2708 | } else if (type_changed || sx != 0 || sy != 0 || |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2709 | es->geometry.width != es->buffer->width || |
| 2710 | es->geometry.height != es->buffer->height) { |
| 2711 | GLfloat from_x, from_y; |
| 2712 | GLfloat to_x, to_y; |
| 2713 | |
| 2714 | weston_surface_to_global_float(es, 0, 0, &from_x, &from_y); |
| 2715 | weston_surface_to_global_float(es, sx, sy, &to_x, &to_y); |
| 2716 | configure(shell, es, |
| 2717 | es->geometry.x + to_x - from_x, |
| 2718 | es->geometry.y + to_y - from_y, |
| 2719 | es->buffer->width, es->buffer->height); |
Ander Conselvan de Oliveira | 093bfa3 | 2012-03-27 17:36:41 +0300 | [diff] [blame] | 2720 | } |
| 2721 | } |
| 2722 | |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2723 | static int launch_desktop_shell_process(struct desktop_shell *shell); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2724 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2725 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2726 | desktop_shell_sigchld(struct weston_process *process, int status) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2727 | { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2728 | uint32_t time; |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2729 | struct desktop_shell *shell = |
| 2730 | container_of(process, struct desktop_shell, child.process); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2731 | |
| 2732 | shell->child.process.pid = 0; |
| 2733 | shell->child.client = NULL; /* already destroyed by wayland */ |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2734 | |
| 2735 | /* if desktop-shell dies more than 5 times in 30 seconds, give up */ |
| 2736 | time = weston_compositor_get_time(); |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 2737 | if (time - shell->child.deathstamp > 30000) { |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2738 | shell->child.deathstamp = time; |
| 2739 | shell->child.deathcount = 0; |
| 2740 | } |
| 2741 | |
| 2742 | shell->child.deathcount++; |
| 2743 | if (shell->child.deathcount > 5) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2744 | weston_log("weston-desktop-shell died, giving up.\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2745 | return; |
| 2746 | } |
| 2747 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2748 | weston_log("weston-desktop-shell died, respawning...\n"); |
Pekka Paalanen | 4d733ee | 2012-01-17 14:36:27 +0200 | [diff] [blame] | 2749 | launch_desktop_shell_process(shell); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | static int |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2753 | launch_desktop_shell_process(struct desktop_shell *shell) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2754 | { |
Kristian Høgsberg | 9724b51 | 2012-01-03 14:35:49 -0500 | [diff] [blame] | 2755 | const char *shell_exe = LIBEXECDIR "/weston-desktop-shell"; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2756 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2757 | shell->child.client = weston_client_launch(shell->compositor, |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 2758 | &shell->child.process, |
| 2759 | shell_exe, |
| 2760 | desktop_shell_sigchld); |
| 2761 | |
| 2762 | if (!shell->child.client) |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2763 | return -1; |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 2764 | return 0; |
| 2765 | } |
| 2766 | |
| 2767 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2768 | bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) |
| 2769 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2770 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2771 | |
| 2772 | wl_client_add_object(client, &wl_shell_interface, |
Pekka Paalanen | 9d1613e | 2011-11-25 12:09:16 +0200 | [diff] [blame] | 2773 | &shell_implementation, id, shell); |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2774 | } |
| 2775 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2776 | static void |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2777 | unbind_desktop_shell(struct wl_resource *resource) |
| 2778 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2779 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2780 | |
| 2781 | if (shell->locked) |
| 2782 | resume_desktop(shell); |
| 2783 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2784 | shell->child.desktop_shell = NULL; |
| 2785 | shell->prepare_event_sent = false; |
| 2786 | free(resource); |
| 2787 | } |
| 2788 | |
| 2789 | static void |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2790 | bind_desktop_shell(struct wl_client *client, |
| 2791 | void *data, uint32_t version, uint32_t id) |
| 2792 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2793 | struct desktop_shell *shell = data; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2794 | struct wl_resource *resource; |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2795 | |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2796 | resource = wl_client_add_object(client, &desktop_shell_interface, |
| 2797 | &desktop_shell_implementation, |
| 2798 | id, shell); |
| 2799 | |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2800 | if (client == shell->child.client) { |
| 2801 | resource->destroy = unbind_desktop_shell; |
| 2802 | shell->child.desktop_shell = resource; |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2803 | return; |
Pekka Paalanen | 9ef3e01 | 2011-11-15 13:34:48 +0200 | [diff] [blame] | 2804 | } |
Pekka Paalanen | bbe6052 | 2011-11-03 14:11:33 +0200 | [diff] [blame] | 2805 | |
| 2806 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2807 | "permission to bind desktop_shell denied"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2808 | wl_resource_destroy(resource); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 2809 | } |
| 2810 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2811 | static void |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 2812 | screensaver_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
| 2813 | { |
| 2814 | struct desktop_shell *shell = surface->private; |
| 2815 | |
| 2816 | if (!shell->locked) |
| 2817 | return; |
| 2818 | |
| 2819 | center_on_output(surface, surface->output); |
| 2820 | |
| 2821 | if (wl_list_empty(&surface->layer_link)) { |
| 2822 | wl_list_insert(shell->lock_layer.surface_list.prev, |
| 2823 | &surface->layer_link); |
| 2824 | weston_surface_assign_output(surface); |
| 2825 | shell->compositor->idle_time = shell->screensaver.duration; |
| 2826 | weston_compositor_wake(shell->compositor); |
| 2827 | shell->compositor->state = WESTON_COMPOSITOR_IDLE; |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | static void |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2832 | screensaver_set_surface(struct wl_client *client, |
| 2833 | struct wl_resource *resource, |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 2834 | struct wl_resource *surface_resource, |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2835 | struct wl_resource *output_resource) |
| 2836 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2837 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 2838 | struct weston_surface *surface = surface_resource->data; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2839 | struct weston_output *output = output_resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2840 | |
Kristian Høgsberg | 1a73a63 | 2012-06-26 22:15:53 -0400 | [diff] [blame] | 2841 | surface->configure = screensaver_configure; |
| 2842 | surface->private = shell; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2843 | surface->output = output; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | static const struct screensaver_interface screensaver_implementation = { |
| 2847 | screensaver_set_surface |
| 2848 | }; |
| 2849 | |
| 2850 | static void |
| 2851 | unbind_screensaver(struct wl_resource *resource) |
| 2852 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2853 | struct desktop_shell *shell = resource->data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2854 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2855 | shell->screensaver.binding = NULL; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2856 | free(resource); |
| 2857 | } |
| 2858 | |
| 2859 | static void |
| 2860 | bind_screensaver(struct wl_client *client, |
| 2861 | void *data, uint32_t version, uint32_t id) |
| 2862 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2863 | struct desktop_shell *shell = data; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2864 | struct wl_resource *resource; |
| 2865 | |
| 2866 | resource = wl_client_add_object(client, &screensaver_interface, |
| 2867 | &screensaver_implementation, |
| 2868 | id, shell); |
| 2869 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2870 | if (shell->screensaver.binding == NULL) { |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2871 | resource->destroy = unbind_screensaver; |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 2872 | shell->screensaver.binding = resource; |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2873 | return; |
| 2874 | } |
| 2875 | |
| 2876 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2877 | "interface object already bound"); |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2878 | wl_resource_destroy(resource); |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 2879 | } |
| 2880 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2881 | static void |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2882 | input_panel_configure(struct weston_surface *surface, int32_t sx, int32_t sy) |
| 2883 | { |
| 2884 | struct weston_mode *mode = surface->output->current; |
| 2885 | GLfloat x = (mode->width - surface->buffer->width) / 2; |
| 2886 | GLfloat y = mode->height - surface->buffer->height; |
| 2887 | |
| 2888 | /* Don't map the input panel here, wait for |
| 2889 | * show_input_panels signal. */ |
| 2890 | |
| 2891 | weston_surface_configure(surface, |
| 2892 | surface->output->x + x, |
| 2893 | surface->output->y + y, |
| 2894 | surface->buffer->width, |
| 2895 | surface->buffer->height); |
| 2896 | } |
| 2897 | |
| 2898 | static void |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2899 | input_panel_set_surface(struct wl_client *client, |
| 2900 | struct wl_resource *resource, |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2901 | struct wl_resource *surface_resource, |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2902 | struct wl_resource *output_resource) |
| 2903 | { |
| 2904 | struct desktop_shell *shell = resource->data; |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2905 | struct weston_surface *surface = surface_resource->data; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2906 | struct weston_output *output = output_resource->data; |
| 2907 | |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2908 | surface->configure = input_panel_configure; |
| 2909 | surface->private = shell; |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2910 | surface->output = output; |
Kristian Høgsberg | 0636ac3 | 2012-06-27 10:22:15 -0400 | [diff] [blame] | 2911 | wl_list_insert(shell->input_panel.surfaces.prev, &surface->layer_link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | static const struct input_panel_interface input_panel_implementation = { |
| 2915 | input_panel_set_surface |
| 2916 | }; |
| 2917 | |
| 2918 | static void |
| 2919 | unbind_input_panel(struct wl_resource *resource) |
| 2920 | { |
| 2921 | struct desktop_shell *shell = resource->data; |
| 2922 | |
| 2923 | shell->input_panel.binding = NULL; |
| 2924 | free(resource); |
| 2925 | } |
| 2926 | |
| 2927 | static void |
| 2928 | bind_input_panel(struct wl_client *client, |
| 2929 | void *data, uint32_t version, uint32_t id) |
| 2930 | { |
| 2931 | struct desktop_shell *shell = data; |
| 2932 | struct wl_resource *resource; |
| 2933 | |
| 2934 | resource = wl_client_add_object(client, &input_panel_interface, |
| 2935 | &input_panel_implementation, |
| 2936 | id, shell); |
| 2937 | |
| 2938 | if (shell->input_panel.binding == NULL) { |
| 2939 | resource->destroy = unbind_input_panel; |
| 2940 | shell->input_panel.binding = resource; |
| 2941 | return; |
| 2942 | } |
| 2943 | |
| 2944 | wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 2945 | "interface object already bound"); |
| 2946 | wl_resource_destroy(resource); |
| 2947 | } |
| 2948 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2949 | struct switcher { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 2950 | struct desktop_shell *shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2951 | struct weston_surface *current; |
| 2952 | struct wl_listener listener; |
| 2953 | struct wl_keyboard_grab grab; |
| 2954 | }; |
| 2955 | |
| 2956 | static void |
| 2957 | switcher_next(struct switcher *switcher) |
| 2958 | { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2959 | struct weston_surface *surface; |
| 2960 | struct weston_surface *first = NULL, *prev = NULL, *next = NULL; |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 2961 | struct shell_surface *shsurf; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2962 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2963 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 2964 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2965 | switch (get_shell_surface_type(surface)) { |
| 2966 | case SHELL_SURFACE_TOPLEVEL: |
| 2967 | case SHELL_SURFACE_FULLSCREEN: |
| 2968 | case SHELL_SURFACE_MAXIMIZED: |
| 2969 | if (first == NULL) |
| 2970 | first = surface; |
| 2971 | if (prev == switcher->current) |
| 2972 | next = surface; |
| 2973 | prev = surface; |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2974 | surface->alpha = 0.25; |
Kristian Høgsberg | cacb7cd | 2012-02-28 09:20:21 -0500 | [diff] [blame] | 2975 | surface->geometry.dirty = 1; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2976 | weston_surface_damage(surface); |
| 2977 | break; |
| 2978 | default: |
| 2979 | break; |
| 2980 | } |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 2981 | |
| 2982 | if (is_black_surface(surface, NULL)) { |
Scott Moreau | 02709af | 2012-05-22 01:54:10 -0600 | [diff] [blame] | 2983 | surface->alpha = 0.25; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 2984 | surface->geometry.dirty = 1; |
| 2985 | weston_surface_damage(surface); |
| 2986 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | if (next == NULL) |
| 2990 | next = first; |
| 2991 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 2992 | if (next == NULL) |
| 2993 | return; |
| 2994 | |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2995 | wl_list_remove(&switcher->listener.link); |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 2996 | wl_signal_add(&next->surface.resource.destroy_signal, |
| 2997 | &switcher->listener); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 2998 | |
| 2999 | switcher->current = next; |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3000 | next->alpha = 1.0; |
Alex Wu | 1659daa | 2012-04-01 20:13:09 +0800 | [diff] [blame] | 3001 | |
Kristian Høgsberg | 32e5686 | 2012-04-02 22:18:58 -0400 | [diff] [blame] | 3002 | shsurf = get_shell_surface(switcher->current); |
| 3003 | if (shsurf && shsurf->type ==SHELL_SURFACE_FULLSCREEN) |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3004 | shsurf->fullscreen.black_surface->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | static void |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3008 | switcher_handle_surface_destroy(struct wl_listener *listener, void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3009 | { |
| 3010 | struct switcher *switcher = |
| 3011 | container_of(listener, struct switcher, listener); |
| 3012 | |
| 3013 | switcher_next(switcher); |
| 3014 | } |
| 3015 | |
| 3016 | static void |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3017 | switcher_destroy(struct switcher *switcher) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3018 | { |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3019 | struct weston_surface *surface; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3020 | struct wl_keyboard *keyboard = switcher->grab.keyboard; |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3021 | struct workspace *ws = get_current_workspace(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3022 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3023 | wl_list_for_each(surface, &ws->layer.surface_list, layer_link) { |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 3024 | surface->alpha = 1.0; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3025 | weston_surface_damage(surface); |
| 3026 | } |
| 3027 | |
Alex Wu | 07b2606 | 2012-03-12 16:06:01 +0800 | [diff] [blame] | 3028 | if (switcher->current) |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3029 | activate(switcher->shell, switcher->current, |
| 3030 | (struct weston_seat *) keyboard->seat); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3031 | wl_list_remove(&switcher->listener.link); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3032 | wl_keyboard_end_grab(keyboard); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3033 | free(switcher); |
| 3034 | } |
| 3035 | |
| 3036 | static void |
| 3037 | switcher_key(struct wl_keyboard_grab *grab, |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3038 | uint32_t time, uint32_t key, uint32_t state_w) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3039 | { |
| 3040 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3041 | enum wl_keyboard_key_state state = state_w; |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3042 | |
Daniel Stone | c9785ea | 2012-05-30 16:31:52 +0100 | [diff] [blame] | 3043 | if (key == KEY_TAB && state == WL_KEYBOARD_KEY_STATE_PRESSED) |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3044 | switcher_next(switcher); |
| 3045 | } |
| 3046 | |
| 3047 | static void |
| 3048 | switcher_modifier(struct wl_keyboard_grab *grab, uint32_t serial, |
| 3049 | uint32_t mods_depressed, uint32_t mods_latched, |
| 3050 | uint32_t mods_locked, uint32_t group) |
| 3051 | { |
| 3052 | struct switcher *switcher = container_of(grab, struct switcher, grab); |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3053 | struct weston_seat *seat = (struct weston_seat *) grab->keyboard->seat; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3054 | |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3055 | if ((seat->modifier_state & switcher->shell->binding_modifier) == 0) |
| 3056 | switcher_destroy(switcher); |
Kristian Høgsberg | b71302e | 2012-05-10 12:28:35 -0400 | [diff] [blame] | 3057 | } |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3058 | |
| 3059 | static const struct wl_keyboard_grab_interface switcher_grab = { |
Daniel Stone | 351eb61 | 2012-05-31 15:27:47 -0400 | [diff] [blame] | 3060 | switcher_key, |
| 3061 | switcher_modifier, |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3062 | }; |
| 3063 | |
| 3064 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3065 | switcher_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3066 | void *data) |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3067 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3068 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3069 | struct switcher *switcher; |
| 3070 | |
| 3071 | switcher = malloc(sizeof *switcher); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3072 | switcher->shell = shell; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3073 | switcher->current = NULL; |
Kristian Høgsberg | 27e3052 | 2012-04-11 23:18:23 -0400 | [diff] [blame] | 3074 | switcher->listener.notify = switcher_handle_surface_destroy; |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3075 | wl_list_init(&switcher->listener.link); |
| 3076 | |
Kristian Høgsberg | b0d8e77 | 2012-06-18 16:34:58 -0400 | [diff] [blame] | 3077 | lower_fullscreen_layer(switcher->shell); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3078 | switcher->grab.interface = &switcher_grab; |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 3079 | wl_keyboard_start_grab(seat->keyboard, &switcher->grab); |
| 3080 | wl_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | 0704539 | 2012-02-19 18:52:44 -0500 | [diff] [blame] | 3081 | switcher_next(switcher); |
| 3082 | } |
| 3083 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3084 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3085 | backlight_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3086 | void *data) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3087 | { |
| 3088 | struct weston_compositor *compositor = data; |
| 3089 | struct weston_output *output; |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 3090 | long backlight_new = 0; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3091 | |
| 3092 | /* TODO: we're limiting to simple use cases, where we assume just |
| 3093 | * control on the primary display. We'd have to extend later if we |
| 3094 | * ever get support for setting backlights on random desktop LCD |
| 3095 | * panels though */ |
| 3096 | output = get_default_output(compositor); |
| 3097 | if (!output) |
| 3098 | return; |
| 3099 | |
| 3100 | if (!output->set_backlight) |
| 3101 | return; |
| 3102 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 3103 | if (key == KEY_F9 || key == KEY_BRIGHTNESSDOWN) |
| 3104 | backlight_new = output->backlight_current - 25; |
| 3105 | else if (key == KEY_F10 || key == KEY_BRIGHTNESSUP) |
| 3106 | backlight_new = output->backlight_current + 25; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3107 | |
Tiago Vignatti | 5ab91ad | 2012-03-12 19:40:09 -0300 | [diff] [blame] | 3108 | if (backlight_new < 5) |
| 3109 | backlight_new = 5; |
| 3110 | if (backlight_new > 255) |
| 3111 | backlight_new = 255; |
| 3112 | |
| 3113 | output->backlight_current = backlight_new; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3114 | output->set_backlight(output, output->backlight_current); |
| 3115 | } |
| 3116 | |
| 3117 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3118 | debug_repaint_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3119 | void *data) |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3120 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3121 | struct desktop_shell *shell = data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3122 | struct weston_compositor *compositor = shell->compositor; |
Kristian Høgsberg | b41c081 | 2012-03-04 14:53:40 -0500 | [diff] [blame] | 3123 | struct weston_surface *surface; |
| 3124 | |
| 3125 | if (shell->debug_repaint_surface) { |
| 3126 | weston_surface_destroy(shell->debug_repaint_surface); |
| 3127 | shell->debug_repaint_surface = NULL; |
| 3128 | } else { |
| 3129 | surface = weston_surface_create(compositor); |
| 3130 | weston_surface_set_color(surface, 1.0, 0.0, 0.0, 0.2); |
| 3131 | weston_surface_configure(surface, 0, 0, 8192, 8192); |
| 3132 | wl_list_insert(&compositor->fade_layer.surface_list, |
| 3133 | &surface->layer_link); |
| 3134 | weston_surface_assign_output(surface); |
| 3135 | pixman_region32_init(&surface->input); |
| 3136 | |
| 3137 | /* Here's the dirty little trick that makes the |
| 3138 | * repaint debugging work: we force an |
| 3139 | * update_transform first to update dependent state |
| 3140 | * and clear the geometry.dirty bit. Then we clear |
| 3141 | * the surface damage so it only gets repainted |
| 3142 | * piecewise as we repaint other things. */ |
| 3143 | |
| 3144 | weston_surface_update_transform(surface); |
| 3145 | pixman_region32_fini(&surface->damage); |
| 3146 | pixman_region32_init(&surface->damage); |
| 3147 | shell->debug_repaint_surface = surface; |
| 3148 | } |
| 3149 | } |
| 3150 | |
| 3151 | static void |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3152 | force_kill_binding(struct wl_seat *seat, uint32_t time, uint32_t key, |
| 3153 | void *data) |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3154 | { |
| 3155 | struct wl_client *client; |
| 3156 | pid_t pid; |
| 3157 | uid_t uid; |
| 3158 | gid_t gid; |
| 3159 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3160 | client = seat->keyboard->focus->resource.client; |
| 3161 | wl_client_get_credentials(client, &pid, &uid, &gid); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3162 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3163 | kill(pid, SIGKILL); |
Kristian Høgsberg | 92a57db | 2012-05-26 13:41:06 -0400 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | static void |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3167 | workspace_up_binding(struct wl_seat *seat, uint32_t time, |
| 3168 | uint32_t key, void *data) |
| 3169 | { |
| 3170 | struct desktop_shell *shell = data; |
| 3171 | unsigned int new_index = shell->workspaces.current; |
| 3172 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 3173 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3174 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3175 | if (new_index != 0) |
| 3176 | new_index--; |
| 3177 | |
| 3178 | change_workspace(shell, new_index); |
| 3179 | } |
| 3180 | |
| 3181 | static void |
| 3182 | workspace_down_binding(struct wl_seat *seat, uint32_t time, |
| 3183 | uint32_t key, void *data) |
| 3184 | { |
| 3185 | struct desktop_shell *shell = data; |
| 3186 | unsigned int new_index = shell->workspaces.current; |
| 3187 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 3188 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3189 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3190 | if (new_index < shell->workspaces.num - 1) |
| 3191 | new_index++; |
| 3192 | |
| 3193 | change_workspace(shell, new_index); |
| 3194 | } |
| 3195 | |
| 3196 | static void |
| 3197 | workspace_f_binding(struct wl_seat *seat, uint32_t time, |
| 3198 | uint32_t key, void *data) |
| 3199 | { |
| 3200 | struct desktop_shell *shell = data; |
| 3201 | unsigned int new_index; |
| 3202 | |
Kristian Høgsberg | ce345b0 | 2012-06-25 21:35:29 -0400 | [diff] [blame] | 3203 | if (shell->locked) |
Kristian Høgsberg | 4476aaf | 2012-06-25 14:03:13 -0400 | [diff] [blame] | 3204 | return; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3205 | new_index = key - KEY_F1; |
| 3206 | if (new_index >= shell->workspaces.num) |
| 3207 | new_index = shell->workspaces.num - 1; |
| 3208 | |
| 3209 | change_workspace(shell, new_index); |
| 3210 | } |
| 3211 | |
| 3212 | |
| 3213 | static void |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3214 | shell_destroy(struct wl_listener *listener, void *data) |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3215 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3216 | struct desktop_shell *shell = |
| 3217 | container_of(listener, struct desktop_shell, destroy_listener); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3218 | struct workspace **ws; |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3219 | |
Pekka Paalanen | 9cf5cc8 | 2012-01-02 16:00:24 +0200 | [diff] [blame] | 3220 | if (shell->child.client) |
| 3221 | wl_client_destroy(shell->child.client); |
| 3222 | |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 3223 | wl_list_remove(&shell->lock_listener.link); |
| 3224 | wl_list_remove(&shell->unlock_listener.link); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3225 | wl_list_remove(&shell->show_input_panel_listener.link); |
| 3226 | wl_list_remove(&shell->hide_input_panel_listener.link); |
Kristian Høgsberg | 88c1607 | 2012-05-16 08:04:19 -0400 | [diff] [blame] | 3227 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3228 | wl_array_for_each(ws, &shell->workspaces.array) |
| 3229 | workspace_destroy(*ws); |
| 3230 | wl_array_release(&shell->workspaces.array); |
| 3231 | |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3232 | free(shell->screensaver.path); |
| 3233 | free(shell); |
| 3234 | } |
| 3235 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3236 | static void |
| 3237 | shell_add_bindings(struct weston_compositor *ec, struct desktop_shell *shell) |
| 3238 | { |
| 3239 | uint32_t mod; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3240 | int i, num_workspace_bindings; |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3241 | |
| 3242 | /* fixed bindings */ |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3243 | weston_compositor_add_key_binding(ec, KEY_BACKSPACE, |
| 3244 | MODIFIER_CTRL | MODIFIER_ALT, |
| 3245 | terminate_binding, ec); |
| 3246 | weston_compositor_add_button_binding(ec, BTN_LEFT, 0, |
| 3247 | click_to_activate_binding, |
| 3248 | shell); |
| 3249 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 3250 | MODIFIER_SUPER | MODIFIER_ALT, |
| 3251 | surface_opacity_binding, NULL); |
| 3252 | weston_compositor_add_axis_binding(ec, WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 3253 | MODIFIER_SUPER, zoom_axis_binding, |
| 3254 | NULL); |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3255 | |
| 3256 | /* configurable bindings */ |
| 3257 | mod = shell->binding_modifier; |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3258 | weston_compositor_add_key_binding(ec, KEY_PAGEUP, mod, |
| 3259 | zoom_key_binding, NULL); |
| 3260 | weston_compositor_add_key_binding(ec, KEY_PAGEDOWN, mod, |
| 3261 | zoom_key_binding, NULL); |
| 3262 | weston_compositor_add_button_binding(ec, BTN_LEFT, mod, move_binding, |
| 3263 | shell); |
| 3264 | weston_compositor_add_button_binding(ec, BTN_MIDDLE, mod, |
| 3265 | resize_binding, shell); |
| 3266 | weston_compositor_add_button_binding(ec, BTN_RIGHT, mod, |
| 3267 | rotate_binding, NULL); |
| 3268 | weston_compositor_add_key_binding(ec, KEY_TAB, mod, switcher_binding, |
| 3269 | shell); |
| 3270 | weston_compositor_add_key_binding(ec, KEY_F9, mod, backlight_binding, |
| 3271 | ec); |
| 3272 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSDOWN, 0, |
| 3273 | backlight_binding, ec); |
| 3274 | weston_compositor_add_key_binding(ec, KEY_F10, mod, backlight_binding, |
| 3275 | ec); |
| 3276 | weston_compositor_add_key_binding(ec, KEY_BRIGHTNESSUP, 0, |
| 3277 | backlight_binding, ec); |
Kristian Høgsberg | 73694c8 | 2012-06-28 14:13:10 -0400 | [diff] [blame] | 3278 | weston_compositor_add_key_binding(ec, KEY_SPACE, mod | MODIFIER_SHIFT, |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 3279 | debug_repaint_binding, shell); |
| 3280 | weston_compositor_add_key_binding(ec, KEY_K, mod, |
| 3281 | force_kill_binding, shell); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3282 | weston_compositor_add_key_binding(ec, KEY_UP, mod, |
| 3283 | workspace_up_binding, shell); |
| 3284 | weston_compositor_add_key_binding(ec, KEY_DOWN, mod, |
| 3285 | workspace_down_binding, shell); |
| 3286 | |
| 3287 | /* Add bindings for mod+F[1-6] for workspace 1 to 6. */ |
| 3288 | if (shell->workspaces.num > 1) { |
| 3289 | num_workspace_bindings = shell->workspaces.num; |
| 3290 | if (num_workspace_bindings > 6) |
| 3291 | num_workspace_bindings = 6; |
| 3292 | for (i = 0; i < num_workspace_bindings; i++) |
| 3293 | weston_compositor_add_key_binding(ec, KEY_F1 + i, mod, |
| 3294 | workspace_f_binding, |
| 3295 | shell); |
| 3296 | } |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3297 | } |
| 3298 | |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 3299 | int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3300 | shell_init(struct weston_compositor *ec); |
Kristian Høgsberg | 6c709a3 | 2011-05-06 14:52:41 -0400 | [diff] [blame] | 3301 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3302 | WL_EXPORT int |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3303 | shell_init(struct weston_compositor *ec) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3304 | { |
Tiago Vignatti | be14326 | 2012-04-16 17:31:41 +0300 | [diff] [blame] | 3305 | struct desktop_shell *shell; |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3306 | struct workspace **pws; |
| 3307 | unsigned int i; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3308 | |
| 3309 | shell = malloc(sizeof *shell); |
| 3310 | if (shell == NULL) |
| 3311 | return -1; |
| 3312 | |
Kristian Høgsberg | f0d9116 | 2011-10-11 22:44:23 -0400 | [diff] [blame] | 3313 | memset(shell, 0, sizeof *shell); |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3314 | shell->compositor = ec; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3315 | |
| 3316 | shell->destroy_listener.notify = shell_destroy; |
| 3317 | wl_signal_add(&ec->destroy_signal, &shell->destroy_listener); |
| 3318 | shell->lock_listener.notify = lock; |
| 3319 | wl_signal_add(&ec->lock_signal, &shell->lock_listener); |
| 3320 | shell->unlock_listener.notify = unlock; |
| 3321 | wl_signal_add(&ec->unlock_signal, &shell->unlock_listener); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3322 | shell->show_input_panel_listener.notify = show_input_panels; |
| 3323 | wl_signal_add(&ec->show_input_panel_signal, &shell->show_input_panel_listener); |
| 3324 | shell->hide_input_panel_listener.notify = hide_input_panels; |
| 3325 | 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] | 3326 | ec->ping_handler = ping_handler; |
Kristian Høgsberg | 82a1d11 | 2012-07-19 14:02:00 -0400 | [diff] [blame] | 3327 | ec->shell_interface.shell = shell; |
Tiago Vignatti | bc052c9 | 2012-04-19 16:18:18 +0300 | [diff] [blame] | 3328 | ec->shell_interface.create_shell_surface = create_shell_surface; |
| 3329 | ec->shell_interface.set_toplevel = set_toplevel; |
Tiago Vignatti | 491bac1 | 2012-05-18 16:37:43 -0400 | [diff] [blame] | 3330 | ec->shell_interface.set_transient = set_transient; |
Kristian Høgsberg | 938b8fa | 2012-05-18 13:46:27 -0400 | [diff] [blame] | 3331 | ec->shell_interface.move = surface_move; |
Kristian Høgsberg | c1693f2 | 2012-05-22 16:56:23 -0400 | [diff] [blame] | 3332 | ec->shell_interface.resize = surface_resize; |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3333 | |
Pekka Paalanen | 77346a6 | 2011-11-30 16:26:35 +0200 | [diff] [blame] | 3334 | wl_list_init(&shell->screensaver.surfaces); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3335 | wl_list_init(&shell->input_panel.surfaces); |
Pekka Paalanen | f0fc70d | 2011-11-15 13:34:54 +0200 | [diff] [blame] | 3336 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3337 | weston_layer_init(&shell->fullscreen_layer, &ec->cursor_layer.link); |
| 3338 | weston_layer_init(&shell->panel_layer, &shell->fullscreen_layer.link); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3339 | weston_layer_init(&shell->background_layer, &shell->panel_layer.link); |
| 3340 | weston_layer_init(&shell->lock_layer, NULL); |
| 3341 | |
| 3342 | wl_array_init(&shell->workspaces.array); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3343 | |
Kristian Høgsberg | 6af8eb9 | 2012-01-25 16:57:11 -0500 | [diff] [blame] | 3344 | shell_configuration(shell); |
Pekka Paalanen | e955f1e | 2011-12-07 11:49:52 +0200 | [diff] [blame] | 3345 | |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 3346 | for (i = 0; i < shell->workspaces.num; i++) { |
| 3347 | pws = wl_array_add(&shell->workspaces.array, sizeof *pws); |
| 3348 | if (pws == NULL) |
| 3349 | return -1; |
| 3350 | |
| 3351 | *pws = workspace_create(); |
| 3352 | if (*pws == NULL) |
| 3353 | return -1; |
| 3354 | } |
| 3355 | activate_workspace(shell, 0); |
| 3356 | |
Jonas Ådahl | 62fcd04 | 2012-06-13 00:01:23 +0200 | [diff] [blame] | 3357 | wl_list_init(&shell->workspaces.animation.link); |
| 3358 | shell->workspaces.animation.frame = animate_workspace_change_frame; |
| 3359 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3360 | if (wl_display_add_global(ec->wl_display, &wl_shell_interface, |
| 3361 | shell, bind_shell) == NULL) |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3362 | return -1; |
| 3363 | |
Kristian Høgsberg | 7584062 | 2011-09-06 13:48:16 -0400 | [diff] [blame] | 3364 | if (wl_display_add_global(ec->wl_display, |
| 3365 | &desktop_shell_interface, |
| 3366 | shell, bind_desktop_shell) == NULL) |
| 3367 | return -1; |
| 3368 | |
Pekka Paalanen | 6e16811 | 2011-11-24 11:34:05 +0200 | [diff] [blame] | 3369 | if (wl_display_add_global(ec->wl_display, &screensaver_interface, |
| 3370 | shell, bind_screensaver) == NULL) |
| 3371 | return -1; |
| 3372 | |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 3373 | if (wl_display_add_global(ec->wl_display, &input_panel_interface, |
| 3374 | shell, bind_input_panel) == NULL) |
| 3375 | return -1; |
| 3376 | |
Kristian Høgsberg | f03a616 | 2012-01-17 11:07:42 -0500 | [diff] [blame] | 3377 | shell->child.deathstamp = weston_compositor_get_time(); |
Pekka Paalanen | 6cd281a | 2011-11-03 14:11:32 +0200 | [diff] [blame] | 3378 | if (launch_desktop_shell_process(shell) != 0) |
| 3379 | return -1; |
| 3380 | |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3381 | shell->pointer_focus_listener.notify = handle_pointer_focus; |
Pekka Paalanen | 43e1ba8 | 2012-06-07 15:07:06 +0300 | [diff] [blame] | 3382 | if (ec->seat->seat.pointer) |
| 3383 | wl_signal_add(&ec->seat->seat.pointer->focus_signal, |
| 3384 | &shell->pointer_focus_listener); |
Kristian Høgsberg | d56bd90 | 2012-06-05 09:58:51 -0400 | [diff] [blame] | 3385 | |
Tiago Vignatti | 0b52d48 | 2012-04-20 18:54:25 +0300 | [diff] [blame] | 3386 | shell_add_bindings(ec, shell); |
Kristian Høgsberg | 0793756 | 2011-04-12 17:25:42 -0400 | [diff] [blame] | 3387 | |
Kristian Høgsberg | 4cca349 | 2011-01-18 07:53:49 -0500 | [diff] [blame] | 3388 | return 0; |
| 3389 | } |